using System;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace CommonModule.Util
{
/// <summary>
/// 邮件类
/// </summary>
public class EmailTool
{
/// <summary>
/// 邮件信息
/// </summary>
private MailMessage mailMessage;
/// <summary>
/// 邮件密码
/// </summary>
private string password;
/// <summary>
/// 简单邮件传输协议客户端
/// </summary>
private SmtpClient smtpClient;
/// <summary>
/// 发送
/// </summary>
public void Send()
{
if (this.mailMessage != null)
{
this.smtpClient = new SmtpClient();
//账号密码
this.smtpClient.Credentials = new NetworkCredential(this.mailMessage.From.Address, this.password);
//传递方式
this.smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
//邮件主机
this.smtpClient.Host = "smtp." + this.mailMessage.From.Host;
this.smtpClient.Send(this.mailMessage);
//this.smtpClient.SendMailAsync
}
}
public void SendMail(string To, string From, string Body, string Title, string Password)
{
this.mailMessage = new MailMessage();
this.mailMessage.To.Add(To);
this.mailMessage.From = new MailAddress(From);
this.mailMessage.Subject = Title;
this.mailMessage.Body = Body;
this.mailMessage.IsBodyHtml = true;
this.mailMessage.BodyEncoding = Encoding.UTF8;
this.mailMessage.Priority = MailPriority.Normal;
this.password = Password;
}
}
}