153 lines
5.5 KiB
C#
153 lines
5.5 KiB
C#
|
/*---------------------------------------------------------------------
|
|||
|
* Copyright (C) 2024 TECHSCAN 版权所有。
|
|||
|
* www.techscan.cn
|
|||
|
*┌──────────────────────────────────┐
|
|||
|
*│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │
|
|||
|
*│ 版权所有:上海太迅自动识别技术有限公司 │
|
|||
|
*└──────────────────────────────────┘
|
|||
|
*
|
|||
|
* 文件名: EmailSend.cs
|
|||
|
* 功能描述: N/A
|
|||
|
* 作者: 26950
|
|||
|
* CLR版本: 4.0.30319.42000
|
|||
|
* 创建时间: 2024/5/24 12:47:40
|
|||
|
* Client: MAYONGLONG
|
|||
|
* 文件版本: V1.0.0
|
|||
|
|
|||
|
===============================版本履历===============================
|
|||
|
* Ver 变更日期 负责人 变更内容
|
|||
|
* V1.0.0 2024/5/24 12:47:40 Myl Create
|
|||
|
*
|
|||
|
======================================================================
|
|||
|
//--------------------------------------------------------------------*/
|
|||
|
|
|||
|
using MimeKit;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace TsSFCDevice.Client.Launch.Common.Email
|
|||
|
{
|
|||
|
public class EmailSend
|
|||
|
{
|
|||
|
#region Fields & Property
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Ctor
|
|||
|
|
|||
|
public EmailSend()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Methods
|
|||
|
public async void SendEmail(string cTitle, string cMessage, string cEmailAddressTo, string cEMailAddressCC, IList<string> lstAttachments, bool bRework = false)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
MailKitHelp vEMail = new MailKitHelp();
|
|||
|
// mail.medtronic.com
|
|||
|
vEMail.SmtpAddress = EmailSendParams.DefaultParams.SmtpAddress;
|
|||
|
|
|||
|
// false
|
|||
|
vEMail.IsSSL = EmailSendParams.DefaultParams.IsSSL;
|
|||
|
|
|||
|
// 25
|
|||
|
vEMail.SmtpPort = EmailSendParams.DefaultParams.SmtpPort;
|
|||
|
|
|||
|
//是否启用无密码模式
|
|||
|
if (EmailSendParams.DefaultParams.EmailNoPass)
|
|||
|
{
|
|||
|
vEMail.IsUseDefaultCredentials = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
vEMail.PassWord = EmailSendParams.DefaultParams.Password;
|
|||
|
}
|
|||
|
|
|||
|
// rs.czopssfc@medtronic.com
|
|||
|
vEMail.FromMailAddress = EmailSendParams.DefaultParams.FromMailAddress;
|
|||
|
|
|||
|
//收件人
|
|||
|
vEMail.ToMailAddress = cEmailAddressTo.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
|||
|
|
|||
|
//抄送
|
|||
|
if (!string.IsNullOrEmpty(cEMailAddressCC))
|
|||
|
{
|
|||
|
vEMail.IsCC = true;
|
|||
|
vEMail.CarbonCopy = cEMailAddressCC.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
|||
|
}
|
|||
|
vEMail.IsBodyHtml = true;
|
|||
|
|
|||
|
#region 发送邮件
|
|||
|
|
|||
|
var rs = await Task.Run(() =>
|
|||
|
{
|
|||
|
#region 添加附件
|
|||
|
if (lstAttachments != null && lstAttachments.Any())
|
|||
|
{
|
|||
|
// 清除历史邮件
|
|||
|
if (vEMail.Attachments != null)
|
|||
|
vEMail.Attachments.Clear();
|
|||
|
|
|||
|
vEMail.IsSendAttachments = true;
|
|||
|
|
|||
|
foreach (string item in lstAttachments)
|
|||
|
{
|
|||
|
MimePart attachment = new MimePart()
|
|||
|
{
|
|||
|
//读取文件,只能用绝对路径
|
|||
|
Content = new MimeContent(File.OpenRead(item), ContentEncoding.Default),
|
|||
|
ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
|
|||
|
ContentTransferEncoding = ContentEncoding.Base64,
|
|||
|
//文件名字
|
|||
|
//FileName = Path.GetFileNameWithoutExtension(item),
|
|||
|
FileName = Path.GetFileName(item),
|
|||
|
};
|
|||
|
|
|||
|
if (vEMail.Attachments == null)
|
|||
|
{
|
|||
|
vEMail.Attachments = new List<MimePart>();
|
|||
|
}
|
|||
|
vEMail.Attachments.Add(attachment);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
vEMail.Body = vEMail.GetHtmlInfoString(cMessage);
|
|||
|
if (!string.IsNullOrEmpty(cTitle))
|
|||
|
{
|
|||
|
vEMail.Title = $"外协{(bRework ? "返工" : "")}订单(供应商:{cTitle})发货通知";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
vEMail.Title = $"外协{(bRework ? "返工" : "")}订单发货通知";
|
|||
|
}
|
|||
|
string result = "";
|
|||
|
var vSendStatus = vEMail.Send(out result);
|
|||
|
if (vSendStatus != MailKitHelp.SendStatus.Success)
|
|||
|
{
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (result.StartsWith("邮件发送成功"))
|
|||
|
{
|
|||
|
}
|
|||
|
}
|
|||
|
return result;
|
|||
|
});
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|