if (timer != null)
{
timer.Stop();
timer.Dispose();
}
}
catch (Exception ex)
{
LogTextHelper.WriteLine(ex.ToString());
}
UpdateFinishStatus();
}
其中具体的邮件发送功能封装在SendJobInfo中,通过判断不同的类型,进行不同的发送操作。
其中最为关键的发送代码,就是如何利用LumiSoft.NET组件来构造相应的邮件对象,下面先先介绍下邮件直投的发送方式,由于该组件封装比较好,直投发送方式很简单:
复制代码 代码如下:
Mail_Message message = Create_PlainText_Html_Attachment_Image(mailTo, mailFrom, mailFromDisplay);
SMTP_Client.QuickSend(message);
其中Create_PlainText_Html_Attachment_Image的封装函数详细内容如下所示:
复制代码 代码如下:
代码
private Mail_Message Create_PlainText_Html_Attachment_Image(string mailTo, string mailFrom, string mailFromDisplay)
{
Mail_Message msg = new Mail_Message();
msg.MimeVersion = "1.0";
msg.MessageID = MIME_Utils.CreateMessageID();
msg.Date = DateTime.Now;
msg.From = new Mail_t_MailboxList();
msg.From.Add(new Mail_t_Mailbox(mailFromDisplay, mailFrom));
msg.To = new Mail_t_AddressList();
msg.To.Add(new Mail_t_Mailbox(mailTo, mailTo));
msg.Subject = mailInfo.Title;
//设置回执通知
string notifyEmail = SystemConfig.Default.DispositionNotificationTo;
if (!string.IsNullOrEmpty(notifyEmail) && ValidateUtil.IsEmail(notifyEmail))
{
msg.DispositionNotificationTo = new Mail_t_Mailbox(notifyEmail, notifyEmail);
}
#region MyRegion
//--- multipart/mixed -----------------------------------
MIME_h_ContentType contentType_multipartMixed = new MIME_h_ContentType(MIME_MediaTypes.Multipart.mixed);
contentType_multipartMixed.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');
MIME_b_MultipartMixed multipartMixed = new MIME_b_MultipartMixed(contentType_multipartMixed);
msg.Body = multipartMixed;
//--- multipart/alternative -----------------------------
MIME_Entity entity_multipartAlternative = new MIME_Entity();
MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative);
contentType_multipartAlternative.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');
MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative(contentType_multipartAlternative);
entity_multipartAlternative.Body = multipartAlternative;
multipartMixed.BodyParts.Add(entity_multipartAlternative);