引用:
using System.Net.Mail;
public class EmailHelper { public static bool SendEmail(string title, string body, string address) { try { MailAddress from = new MailAddress("[email protected]", "xxx"); //发送源邮箱地址和名称 MailAddress to = new MailAddress(address); //接收者邮箱地址 MailMessage message = new MailMessage(from, to); //新建邮件 message.Subject = title; //邮件标题 message.Body = body; //邮件正文 message.IsBodyHtml = true; //邮件正文格式 using (SmtpClient client = new SmtpClient("255.255.255.255", 50)) //服务器和端口号 { client.Credentials = new System.Net.NetworkCredential("xxx", "password"); //用户名和密码 client.Send(message); } return true; } catch (Exception) { return false; } } }
时间: 2024-10-09 03:42:14