二开单据套打文件发送到指定邮箱

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

二开单据套打文件发送到指定邮箱

二开单据套打EXCEL/PDF发送到指定邮箱 需求:Cloud自带的发送套打信息至邮箱的功能需要自行点击发送邮件按钮并且选择收件人,可以在操作插件中(审核后,如果审核时间较长可考虑异步调用此方法)调用此方法将不需要手工去操作实现自动发送邮件(获取用户设置的套打模板),前提是要先配置好邮件服务器并且保证邮件服务器是正常可用的。 实现如下效果: ![image.webp](https://wenku.my7c.com/download/0100f8efd812f8804b1a95a18e34dfa6bf94.webp) 1、插件二开方法 //// <summary> ​ /// 金蝶云发送邮件方法 ctx上下文,fid单据内码,billkey单据主键,billtypeid单据类型id,mailadress收件人地址,title邮件标题,msg邮件内容,yjdata邮件账户设置(BAS_MAILACCOUNTSETTING)数据包,pdf是否发送pdf,excel是否发送excel 引用Kingdee.BOS.ServiceHelper /Kingdee.BOS.Core.Metadata/Kingdee.BOS.Core.Metadata.FormElement ​ /// </summary> ​ /// <param name="ctx"></param> ​ /// <param name="fid"></param> ​ /// <param name="billkey"></param> ​ /// <param name="billtypeid"></param> ​ /// <param name="mailadress"></param> ​ /// <param name="title"></param> ​ /// <param name="msg"></param> ​ /// <param name="yjdata"></param> ​ /// <param name="pdf"></param> ​ /// <param name="excel"></param> ​ /// <returns></returns> ​ public string Sendmail(Context ctx, string fid, string billkey, string billtypeid, string[] mailadress, string title, string msg, Kingdee.BOS.Orm.DataEntity.DynamicObject yjdata, bool pdf, bool excel) ​ { ​ if (yjdata != null) ​ { ​ Kingdee.BOS.Orm.DataEntity.DynamicObject yjdzdata = yjdata["FSENDMAILSERVER"] as Kingdee.BOS.Orm.DataEntity.DynamicObject; ​ string yjdz = null;//邮件地址 ​ int yjdk = 0;//邮件端口 ​ string fwdz = null;//邮件服务器地址 ​ string zh = null;//发送邮件账户 ​ string sqm = null;//授权码 ​ string detdmb = null;//默认套打模板 ​ if (!yjdata["FEmailAddress"].IsNullOrEmptyOrWhiteSpace()) ​ { ​ fwdz = yjdata["FEmailAddress"].ToString(); ​ } ​ if (!yjdata["FUserName"].IsNullOrEmptyOrWhiteSpace()) ​ { ​ zh = yjdata["FUserName"].ToString(); ​ } ​ if (!yjdata["FPassword"].IsNullOrEmptyOrWhiteSpace()) ​ { ​ sqm = yjdata["FPassword"].ToString(); ​ } ​ if (yjdzdata != null) ​ { ​ yjdz = yjdzdata["FMailServer"].ToString(); ​ yjdk = Convert.ToInt32(yjdzdata["FSMTPPort"]); ​ } ​ IDynamicFormView view = this.CreateBillView(ctx, billkey, fid);//服务插件中创建view ​ string paratext = UserParamterServiceHelper.Load(ctx, "NotePrintSetup" + view.BillBusinessInfo.GetForm().Id.ToUpper().GetHashCode().ToString(), ctx.UserId, "");//获取套打设置参数 ​ JArray paras = JArray.Parse(paratext); ​ if (paras != null) ​ { ​ var tdmbs = (from pa in paras where pa["key"].ToString() == billtypeid select pa).ToList(); ​ if (tdmbs.Count > 0) ​ { ​ detdmb = tdmbs[0]["value"].ToString(); ​ } ​ } ​ List<string> bids = new List<string>(); ​ bids.Add(fid); ​ List<string> tdids = new List<string>(); ​ tdids.Add(detdmb); ​ //(view as IDynamicFormViewService).MainBarItemClick("YOL_YJ"); ​ Kingdee.BOS.Core.Import.IImportView importView = view as Kingdee.BOS.Core.Import.IImportView; ​ importView.AddViewSession(); ​ string[] ids = { fid }; ​ string[] cc = null; ​ string exportFileName = null; ​ string pdfExportFileName = null; ​ string excelExportFileName = null; ​ ResultInfo resultInfo = null; ​ DynamicFormViewPlugInProxy service = view.GetService<DynamicFormViewPlugInProxy>(); ​ if (service != null) ​ { ​ InitializeSendMailServiceEventArgs initializeSendMailServiceEventArgs = new InitializeSendMailServiceEventArgs(); ​ service.FireOnInitializeSendMailService(initializeSendMailServiceEventArgs); ​ exportFileName = initializeSendMailServiceEventArgs.ExportFileName; ​ } ​ try ​ { ​ pdfExportFileName = SendMailServiceHelper.GetPdfExportFileName(view, ctx.UserId, ids, detdmb, exportFileName); ​ } ​ catch (Exception) ​ { ​ return "生成pdf失败"; ​ } ​ try ​ { ​ excelExportFileName = SendMailServiceHelper.GetExcelExportFileName(view, ctx.UserId, ids, detdmb, exportFileName); ​ } ​ catch (Exception) ​ { ​ return "生成excel失败"; ​ } ​ try ​ { ​ resultInfo = SendMailServiceHelper.Send(view, ctx.UserId, yjdz, yjdk, false, false, fwdz, zh, sqm, title, msg, mailadress, cc, ids, pdf, pdfExportFileName, excel, excelExportFileName, exportFileName); ​ } ​ catch (Exception ex) ​ { ​ return ex.Message; ​ } ​ if (resultInfo.Successful == true) ​ { ​ return "邮件发送成功!"; ​ } ​ else ​ { ​ return "邮件发送失败!原因:" + resultInfo.Message; ​ } ​ } ​ else ​ { ​ return "参数不能为空!"; ​ } ​ } ​ public IBillView CreateBillView(Context ctx, string key, string id) ​ { ​ // 读取物料的元数据 ​ FormMetadata meta = MetaDataServiceHelper.Load(ctx, key) as FormMetadata; ​ Form form = meta.BusinessInfo.GetForm(); ​ // 创建用于引入数据的单据view ​ Type type = Type.GetType("Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web"); ​ var billView = (IDynamicFormViewService)Activator.CreateInstance(type); ​ // 开始初始化billView: ​ // 创建视图加载参数对象,指定各种参数,如FormId, 视图(LayoutId)等 ​ BillOpenParameter openParam = CreateOpenParameter(ctx, meta, id); ​ // 动态领域模型服务提供类,通过此类,构建MVC实例 ​ var provider = form.GetFormServiceProvider(); ​ billView.Initialize(openParam, provider); ​ billView.LoadData(); ​ (billView as IBillView).CommitNetworkCtrl(); ​ return billView as IBillView; ​ } ​ public BillOpenParameter CreateOpenParameter(Context ctx, FormMetadata meta, string id) ​ { ​ Form form = meta.BusinessInfo.GetForm(); ​ // 指定FormId, LayoutId ​ BillOpenParameter openParam = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id); ​ // 数据库上下文 ​ openParam.Context = ctx; ​ // 本单据模型使用的MVC框架 ​ openParam.ServiceName = form.FormServiceName; ​ // 随机产生一个不重复的PageId,作为视图的标识 ​ openParam.PageId = Guid.NewGuid().ToString(); ​ // 元数据 ​ openParam.FormMetaData = meta; ​ // 界面状态:新增 (修改、查看) ​ openParam.Status = OperationStatus.EDIT; ​ // 单据主键 ​ openParam.PkValue = id; ​ // 界面创建目的:普通无特殊目的 (为工作流、为下推、为复制等) ​ openParam.CreateFrom = CreateFrom.Default; ​ // 基础资料分组维度:基础资料允许添加多个分组字段,每个分组字段会有一个分组维度 ​ // 具体分组维度Id,请参阅 form.FormGroups 属性 ​ openParam.GroupId = ""; ​ // 基础资料分组:如果需要为新建的基础资料指定所在分组,请设置此属性 ​ openParam.ParentId = 0; ​ // 单据类型 ​ openParam.DefaultBillTypeId = ""; ​ // 业务流程 ​ openParam.DefaultBusinessFlowId = ""; ​ // 主业务组织改变时,不用弹出提示界面 ​ openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false); ​ // 插件 ​ List<AbstractDynamicFormPlugIn> plugs = form.CreateFormPlugIns(); ​ openParam.SetCustomParameter(FormConst.PlugIns, plugs); ​ PreOpenFormEventArgs args = new PreOpenFormEventArgs(ctx, openParam); ​ foreach (var plug in plugs) ​ {// 触发插件PreOpenForm事件,供插件确认是否允许打开界面 ​ plug.PreOpenForm(args); ​ } ​ if (args.Cancel == true) ​ {// 插件不允许打开界面 ​ // 本案例不理会插件的诉求,继续.... ​ } ​ // 返回 ​ return openParam; ​ } 2、相关资料 在新发布的V7.6.1.202012灰度补丁中,系统新增发送接口MailUtils.Sendmail(EmailMessageInfo info),该接口支持25/465/587端口,以后会增加更多邮件功能,二开发送邮件时请使用该接口。 EmailMessageInfo 各属性介绍如下 1)邮件发送服务器相关 ``` /// <summary> /// 发送邮件方式 /// </summary> public EmailSendType SendType { get; set; } /// <summary> /// 邮件协议:Auto/POP3/IMAP/HTTP /// </summary> public EmailProtocol Protocol { get; set; } /// <summary> /// Smtp服务器 /// </summary> public string SmtpHost { get; set; } /// <summary> /// 端口号: 25/465/587 /// </summary> public int SmtpPort { get; set; } /// <summary> /// 是否支持SSL /// </summary> public bool EnableSSL { get; set; } ``` 2) 发件人信息相关 ``` /// <summary> /// 发送邮件 /// </summary> public string From { get; set; } /// <summary> /// 发送邮件显示名称 /// </summary> public string FromName { get; set; } /// <summary> /// 邮箱账号 /// </summary> public string UserName { get; set; } /// <summary> /// 邮箱密码,默认为加密字符串 /// </summary> public string Password { get; set; } /// <summary> /// 邮箱密码是否已解密,默认值为false=加密 /// </summary> public bool PwdDecode { get; set; } ``` 以上信息可以通过如下函数直接获取,如果设置正确,只需对返回值设置To/Cc/Subject/Body/Attachments 即可调用MailUtils.Sendmail(EmailMessageInfo info)发送邮件。 ``` // 获取个人信息 -- 邮箱账号设置 SendMailServiceHelper.EmailMessageInfo GetEmailMessageInfoByUserId(Context ctx, long userId); // 获取参数设置-流程中心-工作流 虚拟邮箱配置 SendMailServiceHelper.EmailMessageInfo GetEmailMessageInfoByWfVirtual(Context ctx, long userId = 0); // 获取参数设置-基础管理-BOS平台 虚拟邮箱配置 SendMailServiceHelper.EmailMessageInfo GetEmailMessageInfoByBosVirtual(Context ctx, long userId = 0); ``` 3) 接收人相关: ``` /// <summary> /// 接收邮件 /// </summary> public List<string> To { get; set; } /// <summary> /// 抄送邮件 /// </summary> public List<string> Cc { get; set; } ``` 4) 邮件信息相关 ``` /// <summary> /// 邮件标题 /// </summary> public string Subject { get; set; } /// <summary> /// 邮件内容 /// </summary> public string Body { get; set; } /// <summary> /// 内容是否HTML编码,默认值为true /// </summary> public bool IsBodyHtml { get; set; } /// <summary> /// 附件,表示附件文件的绝对物理路径。推荐使用 /// 实际附件包括Attachments和AttachmentStream /// </summary> public List<string> Attachments { get; set; } /// <summary> /// 附件,表示附件文件名和Stream。兼容旧版本 /// 实际附件包括Attachments和AttachmentStream /// </summary> public List<KeyValuePair<string, Stream>> AttachmentStream { get; set; } ``` 备注:邮件发送失败会抛出异常,请注意处理。 配置邮箱服务器: https://wenku.my7c.com/article/278616582945537792?productLineId=1&lang=zh-CN

二开单据套打文件发送到指定邮箱

二开单据套打EXCEL/PDF发送到指定邮箱需求:Cloud自带的发送套打信息至邮箱的功能需要自行点击发送邮件按钮并且选择收件人,可以在操作插件...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息