// 收件人地址,多个收件人用英文的逗号,隔开
// 邮件标题// 邮件内容
// 对方回复邮件时接收回复的地址
// 附件
public static void SendMail(string to, string title, string content, string replyto, string file)
{
MailMessage message = new MailMessage();
//邮件标题
message.Subject = title;
//邮件内容
message.Body = content;
//发送人的邮箱地址(一定要跟当前使用的账号相同)
message.From = new MailAddress("test@126.com");
//指定邮件被回复时接收回复的地址
if (!string.IsNullOrEmpty(replyto))
{
message.ReplyToList.Add(replyto);
}
//收件人,多个收件人用,隔开
string[] emaillist = to.Split(',');
for (int i = 0; i < emaillist.Length; i++)
{
message.To.Add(new MailAddress(emaillist[i]));
}
//添加附件
if (!string.IsNullOrEmpty(file))
{
message.Attachments.Add(new Attachment(file));
}
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//smtp服务器
client.Host = "smtp.126.com";
client.Port = 465;
//邮箱账号,密码client.Credentials = new System.Net.NetworkCredential("test", "123456");
client.Send(message);
}
ok
mjj通道