从网上找了一个封装.Net的Smtp邮件发送的类
[csharp]
class MailSender
{
private MailMessage mailMessage;
private SmtpClient smtpClient;
private string password;//发件人密码
///
/// 处审核后类的实例
///
/// 收件人地址
/// 发件人地址
/// 邮件正文
/// 邮件的主题
/// 发件人密码
public MailSender(string To, string From, string Body, string Title, string Password)
{
mailMessage = new MailMessage();
mailMessage.To.Add(To);
mailMessage.From = new System.Net.Mail.MailAddress(From);
mailMessage.Subject = Title;
mailMessage.Body = Body;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
this.password = Password;
}
///
/// 添加附件
///
public void Attachments(string Path)
{
string[] path = Path.Split(',');
Attachment data;
ContentDisposition disposition;
for (int i = 0; i < path.Length; i++)
{
data = new Attachment(path[i], MediaTypeNames.Application.Octet);//实例化附件
disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(path[i]);//获取附件的创建日期
disposition.ModificationDate = System.IO.File.GetLastWriteTime(path[i]);//获取附件的修改日期
disposition.ReadDate = System.IO.File.GetLastAccessTime(path[i]);//获取附件的读取日期
mailMessage.Attachments.Add(data);//添加到附件中
}
}
///
/// 异步发送邮件
///
///
public void SendAsync(SendCompletedEventHandler CompletedMethod)
{
if (mailMessage != null)
{
smtpClient = new SmtpClient();
smtpClient.Credentials = new System.Net.NetworkCredential(mailMessage.From.Address, password);//设置发件人身份的票据
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Host = "smtp." + mailMessage.From.Host;
smtpClient.SendCompleted += new SendCompletedEventHandler(CompletedMethod);//注册异步发送邮件完成时的事件
smtpClient.SendAsync(mailMessage, mailMessage.Body);
}
}
///
/// 发送邮件
///
public void Send()
{
if (mailMessage != null)
{
smtpClient = new SmtpClient();
smtpClient.Credentials = new System.Net.NetworkCredential(mailMessage.From.Address, password);//设置发件人身份的票据
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Host = "smtp." + mailMessage.From.Host;
smtpClient.Send(mailMessage);
}
}
}
相关报道:
在Python中,对象是通过名字进行关联和引用的。Python通过名字绑定操作来引入名字。 Python中的所谓的代码块就是一段作为执行单元的程序。比如:模块、函数、类定义。在交互式环境中输入的命令也是代码块的一种。一个Python脚本文件也是一个代码块。还有就是 更多
今天我们先从前端开发领域着手,看看前端开发者可以在这里得到什么?前端开发人员必须了解的七大技能图谱 更多