public class SendEmail
{
///
/// 发送邮件
///
/// 发送方帐号
/// 发送方密码
/// 发送方邮件地址
/// 接收方邮件地址
/// 邮件标题
/// 邮件正文内容
/// 邮件附件
///
public static bool sendMail(MyEmail e)//string strHost, string strAccount, string strPwd, string strFrom, string to, string title, string content
{
//发送方帐号
e.strAccount = "@qq.com";
//发送方密码
e.strPwd = "xxx";
//发送方邮件地址
e.strFrom = "[email protected]";
SmtpClient smtpClient = new SmtpClient("smtp.qq.com", 25);
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
smtpClient.Credentials = new System.Net.NetworkCredential(e.strAccount, e.strPwd);//用户名和密码
MailMessage mailMessage = new MailMessage(e.strFrom, e.to);
mailMessage.Subject = e.title;//主题
mailMessage.Body = e.content;//内容
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
mailMessage.IsBodyHtml = true;//设置为HTML格式
mailMessage.Priority = MailPriority.High;//优先级
//// 添加附件
if (e.sfile != "")
{
mailMessage.Attachments.Add(new Attachment(e.sfile));
}
try
{
smtpClient.Send(mailMessage);
mailMessage.Dispose();//释放资源
return true;
}
catch (Exception ex)
{
Common.Log.Instance.Error(typeof(string), "邮件发送错误:"+ex.Message);
return false;
}
}
public class MyEmail
{
///
/// 发送方帐号
///
public string strAccount { get; set; }
///
/// 发送方密码
///
public string strPwd { get; set; }
///
/// 发送方邮件地址
///
public string strFrom { get; set; }
///
/// 接收方邮件地址
///
public string to { get; set; }
///
/// 邮件标题
///
public string title { get; set; }
///
/// 邮件正文内容
///
public string content { get; set; }
///
/// 附件
///
public string sfile { get; set; }
}
}
protected bool Send(string email, string reportImage, string resultImage)
{
bool result = false;
SendEmail.MyEmail myEmail = new SendEmail.MyEmail();
//接收方邮件地址
myEmail.to = email;
//邮件标题
myEmail.title = "芮老师测试报告";
//邮件正文内容
var htmlContent = $@"测试报告:
" +
$"测试结果:
";
myEmail.content = htmlContent;
//附件
myEmail.sfile = "";
result = SendEmail.sendMail(myEmail);
return result;
}
原文:https://blog.csdn.net/xufei512/article/details/79009922
gmail(google.com)
POP3服务器地址:pop.gmail.com(SSL启用 端口:995)
SMTP服务器地址:smtp.gmail.com(SSL启用 端口:587)
21cn.com:
POP3服务器地址:pop.21cn.com(端口:110)
SMTP服务器地址:smtp.21cn.com(端口:25)
sina.com:
POP3服务器地址:pop3.sina.com.cn(端口:110)
SMTP服务器地址:smtp.sina.com.cn(端口:25)
tom.com:
POP3服务器地址:pop.tom.com(端口:110)
SMTP服务器地址:smtp.tom.com(端口:25)
163.com:
POP3服务器地址:pop.163.com(端口:110)
SMTP服务器地址:smtp.163.com(端口:25)
263.net:
POP3服务器地址:pop3.263.net(端口:110)
SMTP服务器地址:smtp.263.net(端口:25)
yahoo.com:
POP3服务器地址:pop.mail.yahoo.com
SMTP服务器地址:smtp.mail.yahoo.com
263.net.cn:
POP3服务器地址:pop.263.net.cn(端口:110)
SMTP服务器地址:smtp.263.net.cn(端口:25)
Foxmail:
POP3服务器地址:POP.foxmail.com(端口:110)
SMTP服务器地址:SMTP.foxmail.com(端口:25)
sinaVIP
POP3服务器:pop3.vip.sina.com (端口:110)
SMTP服务器:smtp.vip.sina.com (端口:25)
sohu.com:
POP3服务器地址:pop3.sohu.com(端口:110)
SMTP服务器地址:smtp.sohu.com(端口:25)
etang.com:
POP3服务器地址:pop.etang.com
SMTP服务器地址:smtp.etang.com
x263.net:
POP3服务器地址:pop.x263.net(端口:110)
SMTP服务器地址:smtp.x263.net(端口:25)
yahoo.com.cn:
POP3服务器地址:pop.mail.yahoo.com.cn(端口:995)
SMTP服务器地址:smtp.mail.yahoo.com.cn(端口:587)
雅虎邮箱POP3的SSL不启用端口为110,POP3的SSL启用端口995;SMTP的SSL不启用端口为25,SMTP的SSL启用端口为465
QQ邮箱 QQ企业邮箱
POP3服务器地址:pop.qq.com(端口:110) POP3服务器地址:pop.exmail.qq.com (SSL启用 端口:995)
SMTP服务器地址:smtp.qq.com (端口:25) SMTP服务器地址:smtp.exmail.qq.com(SSL启用 端口:587/465)
SMTP服务器需要身份验证
126邮箱 HotMail
POP3服务器地址:pop.126.com(端口:110) POP3服务器地址:pop.live.com (端口:995)
SMTP服务器地址:smtp.126.com(端口:25) SMTP服务器地址:smtp.live.com (端口:587)
china.com: 139邮箱
POP3服务器地址:pop.china.com(端口:110) POP3服务器地址:POP.139.com(端口:110)
SMTP服务器地址:smtp.china.com(端口:25) SMTP服务器地址:SMTP.139.com(端口:25)