#region 邮件操作
/// <summary>
/// 获取MailMessage,邮件对象
/// </summary>
/// <param name="from">发件人</param>
/// <param name="to">收件人</param>
/// <param name="subject">邮件主题</param>
/// <param name="body">邮件正文</param>
/// <param name="bodyFormat">邮件发送方式:html:以html方式发送;默认以text方式发送</param>
/// <param name="priority">邮件优先级("0":高优先级;"1":普通优先级;"2":低优先级;默认:普通优先级</param>
/// <returns></returns>
private MailMessage GetMailMessage(string from,string password,string to, string subject,string body,string bodyFormat,string priority)
{
MailMessage mail = new MailMessage();
mail.From = from;
mail.To = to;
mail.Subject = subject;
mail.Body = body;
mail.BodyFormat = (bodyFormat == "html" ? MailFormat.Html : MailFormat.Text);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", from); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //set your password here
switch(priority)
{
case "0" : mail.Priority = MailPriority.High;break;
case "1" : mail.Priority = MailPriority.Normal;break;
case "2" : mail.Priority = MailPriority.Low;break;
default:mail.Priority = MailPriority.Normal;break;
}
return mail;
}
private MailMessage GetMailMessage(string from,string to,string password,string subject,string body)
{
MailMessage mail = GetMailMessage(from,to,password,subject,body,"text","1");
return mail;
}
private void Send(string smtpServer, MailMessage mail)
{
SmtpMail.SmtpServer = smtpServer;
SmtpMail.Send(mail);
}
#endregion