设置右键服务器地址
string senderServerIp =
"123.125.50.133";//smtp
.163.com发件箱的邮件服务器地址
//
string senderServerIp =
"74.125.127.109"; //smtp.gmail.com发件箱的邮件服务器地址
//
string senderServerIp =
"58.251.149.147";//smtp.qq.com发件箱的邮件服务器地址
//
string senderServerIp =
"smtp.sina.com";//smtp.qq.com发件箱的邮件服务器地址
邮件发送方法,直接上代码
public static void SendEmail(MailAddress fromEmail, MailAddress mailAddress,
string subject,
string body,
bool IsBodyHtml, Attachment att,
string server, NetworkCredential networkCredential)
{
try
{
MailMessage msg =
new MailMessage();
msg.From = fromEmail;
msg.Subject = subject;
msg.Priority = MailPriority.Normal;
msg.Body = body;
msg.To.Add(mailAddress);
msg.IsBodyHtml =
true;
if (att !=
null)
{
msg.Attachments.Add(att);
}
SmtpClient client =
new SmtpClient(server,
25);
client.Credentials = networkCredential;
client.EnableSsl =
true;
client.Send(msg);
NlogTools.LogDebug(networkCredential.UserName+
"发送邮件成功!");
}
catch (Exception ex)
{
NlogTools.LogError(ex.Message);
}
}
转载请注明原文地址: https://ju.6miu.com/read-970137.html