需引用的命名空间:
using System.NET.Mail;
using System.IO;
using System.NET;
//设置邮件协议
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式(网络的方式)
client.Host = host;//邮件服务器,一般为smtp.名称.com
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(userName, password);//用户名、密码
//实例化邮件对象
MailMessage mmsg = new MailMessage();
//获取或设置邮件的发件人地址(账号、显示内容)
mmsg.From = new MailAddress(SmtpForm, SmtpDisplay);
foreach (string _item in msgToEmail.Split(';'))
{
if (string.IsNullOrEmpty(_item.Trim())) continue;
mmsg.To.Add(_item);//收件人12345678@qq.com
mmsg.CC.Add(toAddress);//抄送
mmsg.Bcc.Add(toAddress);//密送
}
mmsg.Subject = EmailSubject;//邮件主题
``` swift
网友评论