发送Email 附件打包,
MailAddress fromAddress = new MailAddress("sender@meihua.info", "明道", Encoding.GetEncoding("utf-8"));
StringBuilder sb = new StringBuilder("");
//发送者
System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(user.Email);
MailMessage message = new MailMessage(fromAddress, toAddress);
message.Subject = "管理员" + fromUser.Fullname + "发布的通告";
message.Body = sb.ToString();
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.GetEncoding("utf-8");
message.SubjectEncoding = Encoding.GetEncoding("utf-8");
if (!string.IsNullOrEmpty(filePath))
{
//附件
System.Net.Mail.Attachment mailAttachment = new System.Net.Mail.Attachment(filePath);
if (mailAttachment != null)
message.Attachments.Add(mailAttachment);
//foreach (string attachment in attachments) //循环附件
//{
// System.Net.Mail.Attachment newAttachment = new System.Net.Mail.Attachment(attachment);
// if (newAttachment != null)
// message.Attachments.Add(newAttachment);
//}
}
try
{
MailAddress from = new MailAddress(message.From.Address, message.From.DisplayName, Encoding.GetEncoding("utf-8"));
message.From = from;
message.IsBodyHtml = isBodyHtml;
message.BodyEncoding = Encoding.GetEncoding("utf-8");
message.SubjectEncoding = Encoding.GetEncoding("utf-8");
SmtpClient client = new SmtpClient("mail.meihua.info");
client.Credentials = new System.Net.NetworkCredential("sender", "111111");
client.Send(message);
}
catch {}