|
|
|
@ -21,7 +21,8 @@ namespace Myshipping.Core.Helper
|
|
|
|
|
/// <param name="subject"></param>
|
|
|
|
|
/// <param name="body"></param>
|
|
|
|
|
/// <param name="sendTo"></param>
|
|
|
|
|
public static async Task<KeyValuePair<bool, string>> SendMail(DjyUserMailAccount acc, string subject, string body, string sendTo)
|
|
|
|
|
/// <param name="attachList">附件列表,key为附件名称,value为文件字节数组</param>
|
|
|
|
|
public static async Task<KeyValuePair<bool, string>> SendMail(DjyUserMailAccount acc, string subject, string body, string sendTo, params KeyValuePair<string, byte[]>[] attachList)
|
|
|
|
|
{
|
|
|
|
|
SmtpClient client = null;
|
|
|
|
|
try
|
|
|
|
@ -58,16 +59,33 @@ namespace Myshipping.Core.Helper
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message.Subject = subject;
|
|
|
|
|
message.Sender = MailboxAddress.Parse(acc.MailAccount);
|
|
|
|
|
|
|
|
|
|
var html = new TextPart("html")
|
|
|
|
|
{
|
|
|
|
|
Text = body
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MimeEntity entity = html;
|
|
|
|
|
if (attachList != null && attachList.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var mult = new Multipart("mixed") { html };
|
|
|
|
|
|
|
|
|
|
message.Sender = MailboxAddress.Parse(acc.MailAccount);
|
|
|
|
|
message.Body = entity;
|
|
|
|
|
foreach (var item in attachList)
|
|
|
|
|
{
|
|
|
|
|
var attPart = new MimePart();
|
|
|
|
|
attPart.Content = new MimeContent(new MemoryStream(item.Value));
|
|
|
|
|
attPart.ContentDisposition = new ContentDisposition(ContentDisposition.Attachment);
|
|
|
|
|
attPart.ContentTransferEncoding = ContentEncoding.Base64;
|
|
|
|
|
attPart.FileName = "=?UTF-8?B?" + Convert.ToBase64String(Encoding.UTF8.GetBytes(item.Key)) + "?=";
|
|
|
|
|
mult.Add(attPart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message.Body = mult;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
message.Body = html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (client = new SmtpClient())
|
|
|
|
|
{
|
|
|
|
|