其他分享
首页 > 其他分享> > MailHelper

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);
        }
    }
}

 

标签:string,mailMessage,MailHelper,System,new,using,Net
来源: https://blog.csdn.net/u013073747/article/details/116643725