首页 > 代码库 > C# 发送电子邮件

C# 发送电子邮件

 

/// <summary>
/// 发送电子邮件
/// </summary>
/// <param name="from">发件人</param>
/// <param name="to">收件人</param>
/// <param name="subject">邮件主题</param>
/// <param name="body">邮件内容</param>
/// <param name="host">发送服务地址(smtp.qq.com)</param>
/// <param name="port">发送邮件服务器端口(25) int型</param>
/// <param name="userName">用户名</param>
/// <param name="password">密码</param>
public void Send(string from, string to, string subject, string body, string host, int port, string userName, string password)
{
MailMessage message = new MailMessage(from, to, subject, body);
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient(host, port);
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.Send(message);
}

 

C# 发送电子邮件