二开插件如何使用邮件服务器配置信息及邮件虚拟账户发送邮件
private string DoProclaimText(string CipherText)
{
string result;
if (StringUtils.IsEmpty(CipherText))
{
result = CipherText;
}
else
{
byte[] bytes = Encoding.BigEndianUnicode.GetBytes(CipherText);
int num = bytes.Length;
byte[] array = new byte[num / 2];
for (int i = 0; i < num; i += 4)
{
byte b = bytes[i + 1];
byte b2 = bytes[i + 3];
int num2 = (int)(b & 15) << 4;
int num3 = (int)(b & 240);
int num4 = (int)(b2 & 15);
int num5 = (b2 & 240) >> 4;
array[i / 2] = Convert.ToByte(num2 | num5);
array[i / 2 + 1] = Convert.ToByte(num3 | num4);
}
result = Encoding.BigEndianUnicode.GetString(array, 0, array.Length);
}
return result;
}
private void SendInventoryMail(Context ctx, Kingdee.BOS.Core.Schedule schedule,List<long> SendUserId,string title,string message)
{
ISystemParameterService sysService = Kingdee.BOS.Contracts.ServiceFactory.GetSystemParameterService(ctx);
//此处加载系统参数,获取配置的邮件虚拟账户信息
DynamicObject inquirySysParam = sysService.Load(ctx, ctx.CurrentOrganizationInfo.ID, 0, "SAL_SystemParameter");
string mailFid = "";
if (inquirySysParam != null && inquirySysParam.DynamicObjectType.Properties.ContainsKey("SendMail"))
mailFid = Convert.ToString(inquirySysParam["SendMail_Id"]);
else
return;
//根据配值ID,获取对应的配值服务信息 //发件人账号、密码、发件地址、SSL等
string strSql = string.Format(@"SELECT FEMAILADDRESS,FUSERNAME,FPASSWORD,TSER.FMAILSERVER,FMESSAGETYPE,FSMTPPORT,FSSL FROM T_BAS_MAILVIRTUALACCOUNT TMAIL
INNER JOIN T_BAS_MAILSERVER TSER ON TMAIL.FMAILSERVER = TSER.FID WHERE TMAIL.FID = {0}", mailFid);
DynamicObjectCollection mailInfos = DBUtils.ExecuteDynamicObject(ctx, strSql, null, null, System.Data.CommandType.Text, null);
if (mailInfos == null || mailInfos.Count <= 0)
return;
DynamicObject mailInfo = mailInfos.FirstOrDefault();
string senderMailAddress = Convert.ToString(mailInfo["FEMAILADDRESS"]);
//string title = e.WarnMessage.MobileTitle;
string SMTPHost = Convert.ToString(mailInfo["FMAILSERVER"]);
int port = Convert.ToInt32(mailInfo["FSMTPPORT"]);
bool isSSL = Convert.ToInt32(mailInfo["FSSL"]) == 1;
string userName = Convert.ToString(mailInfo["FUSERNAME"]);
string pwd = DoProclaimText(Convert.ToString(mailInfo["FPASSWORD"]));
//此处根据员工信息获取接收人邮箱信息,也可根据用户ID,找到用户的Email,具体视情况而定
string emailSql = string.Format(@"select FEMAIL,FID from T_HR_EMPINFO where FID in ({0})", string.Join(",", SendUserId));
DynamicObjectCollection mailLst = DBUtils.ExecuteDynamicObject(ctx, emailSql, null, null, System.Data.CommandType.Text, null);
foreach (var item in mailLst)
{
try
{
var listTo = new List<string>();
var userEmail = Convert.ToString(item["FEMAIL"]);
if (string.IsNullOrEmpty(userEmail))
continue;
listTo.Add(userEmail);
////发送附件
//var bytes = Encoding.Default.GetBytes(DataTableToStringBuilder(dt).ToString());
//MemoryStream memory = new MemoryStream(bytes);
//title = "";
//message = "";
////内容
//string body = string.Format("{0}", DateTime.Now.ToString("yyyyMMddHHmmss"));
////附件<文件名, 文件stream>
//Dictionary<string, Stream> dictStream = new Dictionary<string, Stream>();
//dictStream[string.Format("{0}.xls", body)] = memory;
MailUtils.Sendmail(senderMailAddress, null, listTo, title, message, SMTPHost, port, isSSL, null, userName, pwd);
}
catch (Exception ex)
{
ILogService logService = Kingdee.BOS.Contracts.ServiceFactory.GetLogService(ctx);
Kingdee.BOS.Core.Log.LogObject log = new Kingdee.BOS.Core.Log.LogObject();
log.Description = ex.Message;
logService.WriteLog(ctx, log);
}
}
}
二开插件如何使用邮件服务器配置信息及邮件虚拟账户发送邮件
本文2024-09-16 17:52:27发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-18497.html