发邮件代码
using System.Net.Mail;
MailMessage m = new MailMessage();
string FromEmail = "";
string FromEmailPass = "";
m.Body = "内容";
m.Subject = "邮件标题";
m.From = new MailAddress(FromEmail,"自定义显示");
m.To.Add("to1@qq.com");
m.To.Add("to2@qq.com");
#region 不需要改动
m.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
m.IsBodyHtml = true; //是否为html格式
m.Priority = MailPriority.High; //发送邮件的优先等级
m.IsBodyHtml = true;
m.Priority = MailPriority.Normal;
m.SubjectEncoding = System.Text.Encoding.UTF8;
m.BodyEncoding = System.Text.Encoding.UTF8;
#endregion
SmtpClient sc = new SmtpClient();
sc.Host = "smtp.qq.com"; //不同的邮箱对应的值不同
sc.EnableSsl = false;//**
sc.UseDefaultCredentials = false;//**
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = new System.Net.NetworkCredential(FromEmail, FromEmailPass); //指定登录服务器的用户名和密码
try
{
sc.Send(m);
}
catch (Exception ex)
{
string a = ex.ToString();
}