二开执行计划发送邮件示例
客户二开执行计划,执行成功或者失败想实现发送邮件的功能,可以在Run方法里面实现。
需要注意两点:
1,在Run方法里面捕捉异常,发送邮件后,不能吃掉异常信息
2,发送邮件异常,不要抛出异常,此时可以记录异常日志。
using Kingdee.BOS; using Kingdee.BOS.Contracts; using Kingdee.BOS.Core; using Kingdee.BOS.Core.Msg; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Workflow.Contracts; using Kingdee.BOS.WorkflowMember; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Kingdee.Test { public class CustomService : IScheduleService { public void Run(Context ctx, Schedule schedule) { try { DoBusiness(); } catch (Exception ex) { SendEmail(ctx, false); throw ex; //不能吃掉异常 } SendEmail(ctx, true); } /// <summary> /// 发送邮件,如果配置了虚拟邮箱并且开启参数,则虚拟邮箱作为发送人账号,否则按指定发送人作为发送账号 /// </summary> /// <param name="ctx"></param> /// <param name="isSucess"></param> public void SendEmail(Context ctx, bool isSucess) { try { Kingdee.BOS.Core.Msg.Message msg = new DynamicObject(Message.MessageDynamicObjectType); Kingdee.BOS.Contracts.IDBService dbService = Kingdee.BOS.App.ServiceHelper.GetService<Kingdee.BOS.Contracts.IDBService>(); msg.MessageId = dbService.GetSequenceString(1)[0]; msg.ReceiverId = 888888; msg.Title = "执行计划执行"; msg.Content = isSucess ? "执行计划执行成功" : "执行计划执行失败"; msg.SenderId = 12345; //发送人 UserMember sender = new UserMember { Id = "12345", Name = "张三" }; //接收人 UserMember receiver = new UserMember { Id = "888888", Name = "李四" }; IEnumerable<UserMember> receivers = new List<UserMember> { receiver }; IMessageService msgService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetMessageService(ctx); msgService.SendEmailWithParam(ctx, sender, msg, receivers); } catch (Exception ex) { //捕捉异常,不能抛出 } } private void DoBusiness() { } } }
二开执行计划发送邮件示例
客户二开执行计划,执行成功或者失败想实现发送邮件的功能,可以在Run方法里面实现。需要注意两点:1,在Run方法里面捕捉异常,发送邮件后...
点击下载文档
本文2024-09-23 04:21:33发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164797.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章