码迷,mamicode.com
首页 > 其他好文 > 详细

email

时间:2016-09-12 12:18:26      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

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;
}
}
}

email

标签:

原文地址:http://www.cnblogs.com/zhang-wenbin/p/5864079.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!