using System;
using SystemNet;
using SystemNetMail;
using SystemNetMime;
namespace LBCEmail
{
/// <summary>
/// 发送邮件的类
/// </summary>
public class SendMail
{
private MailMessage mailMessage;
private SmtpClient smtpClient;
private string password;//发件人密码
/// <summary>
/// 处审核后类的实例
/// </summary>
/// <param name=To>收件人地址</param>
/// <param name=From>发件人地址</param>
/// <param name=Body>邮件正文</param>
/// <param name=Title>邮件的主题</param>
/// <param name=Password>发件人密码</param>
public SendMail(string To string From string Body string Title string Password)
{
mailMessage = new MailMessage();
mailMessageToAdd(To);
mailMessageFrom = new SystemNetMailMailAddress(From);
mailMessageSubject = Title;
mailMessageBody = Body;
mailMessageIsBodyHtml = true;
mailMessageBodyEncoding = SystemTextEncodingUTF;
mailMessagePriority = SystemNetMailMailPriorityNormal;
thispassword = Password;
}
/// <summary>
/// 添加附件
/// </summary>
public void Attachments(string Path)
{
string[] path = PathSplit();
Attachment data;
ContentDisposition disposition;
for (int i = ; i < pathLength; i++)
{
data = new Attachment(path[i] MediaTypeNamesApplicationOctet);//实例化附件
disposition = dataContentDisposition;
dispositionCreationDate = SystemIOFileGetCreationTime(path[i]);//获取附件的创建日期
dispositionModificationDate = SystemIOFileGetLastWriteTime(path[i]);//获取附件的修改日期
dispositionReadDate = SystemIOFileGetLastAccessTime(path[i]);//获取附件的读取日期
mailMessageAttachmentsAdd(data);//添加到附件中
}
}
/// <summary>
/// 异步发送邮件
/// </summary>
/// <param name=CompletedMethod></param>
public void SendAsync(SendCompletedEventHandler CompletedMethod)
{
if (mailMessage != null)
{
smtpClient = new SmtpClient();
smtpClientCredentials = new SystemNetNetworkCredential(mailMessageFromAddress password);//设置发件人身份的票据
smtpClientDeliveryMethod = SystemNetMailSmtpDeliveryMethodNetwork;
smtpClientHost = smtp + mailMessageFromHost;
smtpClientSendCompleted += new SendCompletedEventHandler(CompletedMethod);//注册异步发送邮件完成时的事件
smtpClientSendAsync(mailMessage mailMessageBody);
}
}
/// <summary>
/// 发送邮件
/// </summary>
public void Send()
{
if (mailMessage != null)
{
smtpClient = new SmtpClient();
smtpClientCredentials = new SystemNetNetworkCredential(mailMessageFromAddress password);//设置发件人身份的票据
smtpClientDeliveryMethod = SystemNetMailSmtpDeliveryMethodNetwork;
smtpClientHost = smtp + mailMessageFromHost;
smtpClientSend(mailMessage);
}
}
}
}