using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
namespace Muchinfo.PC.Common.Helpers
{
public class MailSendHelper
{
///
/// 客户端发送邮件
///
/// 收件人邮箱地址,多个收件人用;隔开
/// 发送人邮箱地址
/// 发送人邮箱密码
/// 服务器
/// 端口
/// 默认发送人名称
/// 主题
/// 内容
/// 附件地址,多个附件用;隔开
public static bool MailSend(
string ToAddress,
string Address,
string Password,
string Host,
int port,
string DisplayName,
string Title,
string Content,
string Attachments,
out string Error)
{
Error = "";
char[] ch = new char[] { ';' };
try
{
MailMessage ms = new MailMessage();
foreach (string str in ToAddress.Split(ch))
{
ms.To.Add(str);
}
ms.From = new MailAddress(Address, DisplayName, System.Text.Encoding.UTF8);
ms.Priority = MailPriority.High;
ms.Subject = Title;
ms.SubjectEncoding = System.Text.Encoding.UTF8;
ms.Body = Content;
if (!string.IsNullOrWhiteSpace(Attachments))
{
foreach (string str in Attachments.Split(ch))
{
Attachment ath = new Attachment(str);
ms.Attachments.Add(ath);
}
}
ms.BodyEncoding = System.Text.Encoding.UTF8;
ms.IsBodyHtml = false;
SmtpClient sc = new SmtpClient();
sc.Credentials = new System.Net.NetworkCredential(Address, Password);
sc.Host = Host;
sc.Port = port;
sc.Send(ms);
return true;
}
catch (Exception ex)
{
Error = ex.Message;
return false;
}
}
}
}