MailHelper

2021/5/11 10:57:43

本文主要是介绍MailHelper,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace OnlineExamination.Utility
{
    public static class MailHelper
    {
        public static void SendMail(string titleText,string bodyText,params string[]targetMail) {
            //邮件主题内容
            MailMessage mailMessage = new MailMessage();//注意:引用System.Net.Mail
            mailMessage.From = new MailAddress("***@qq.com", "显示名称");
            for (int i = 0; i < targetMail.Length; i++)
            {
                mailMessage.To.Add(targetMail[i]);
            }
            mailMessage.Subject = titleText;
            mailMessage.Body = bodyText;
            //调用smtp服务器
            SmtpClient client = new SmtpClient("smtp.qq.com");
            client.Credentials = new NetworkCredential("账号", "密码");
            client.Send(mailMessage);
        }
    }
}

 



这篇关于MailHelper的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程