二开(代码) 采购订单审核发送邮件给供应商联系人邮箱原创
金蝶云社区-霹雳太史侯
霹雳太史侯
14人赞赏了该文章 488次浏览 未经作者许可,禁止转载编辑于2023年08月28日 08:11:09
 System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            string username = "邮箱账号";
            string fromname = "邮箱用户名";
            ////解密密码
            string password = string.Empty;
            //mail.From = new MailAddress(username, fromname, System.Text.Encoding.UTF8); //添加发送人

         
            mail.SubjectEncoding = System.Text.Encoding.UTF8; //邮件标题编码
            mail.BodyEncoding = System.Text.Encoding.UTF8; //邮件内容编码
            mail.IsBodyHtml = true; //是否是HTML邮件
            mail.Priority = MailPriority.Normal; //邮件优先级

            //添加附件
            //string filePath = PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, filename);
            Attachment mailattachment = new Attachment(filePath);
            mail.Attachments.Add(mailattachment);

            //设置邮件标题
            mail.Subject = docno + gysname;


            //设置邮件内容 BODY
            if (cgorgid == 101649)
            {
                username = "7777@qq.com";
                fromname = "赵四";
                password = "a123456";
                mail.From = new MailAddress(username, fromname, System.Text.Encoding.UTF8); //添加发送人
                mail.Body = "XXXX";
            }
            else if (cgorgid == 100911)
            {
                username = "9999@qq.com";
                fromname = "李四";
                password = "a123456";
                mail.From = new MailAddress(username, fromname, System.Text.Encoding.UTF8); //添加发送人
                mail.Body = "XXXX";
            }
            else if (cgorgid == 100909)
            {
                username = "8888@qq.com";
                fromname = "张三";
                password = "a123456";
                mail.From = new MailAddress(username, fromname, System.Text.Encoding.UTF8); //添加发送人 测试邮箱
                mail.Body = "XXXX";

            }


            //获取供应商联系人邮箱
            FormMetadata meta = MetaDataServiceHelper.Load(this.Context, "BD_Supplier") as FormMetadata;
            DynamicObject gysObject = BusinessDataServiceHelper.LoadSingle(this.Context, gysid, meta.BusinessInfo.GetDynamicObjectType());
            //获取供应商联系人 单据体
            var lxrOB = gysObject["SupplierContact"] as DynamicObjectCollection;//联系人
            foreach (var lxr in lxrOB)
            {
                string em = lxr["EMail"] == null ? "" : lxr["EMail"].ToString();
                bool issend1 = (bool)lxr["FISMAIL"];//是否发送邮件标记
                if (!string.IsNullOrWhiteSpace(em) && issend1)
                {
                    mail.To.Add(em);
                }
            }

            //设置邮件抄送人
            if (!string.IsNullOrWhiteSpace(cjrmail))
            {
                mail.CC.Add("6666@qq.com");
            }
           
            
            //设置密送人
            mail.Bcc.Add("XXXX@qq.com");
            

            SmtpClient client = new SmtpClient();
            client.Port = 587; //Gmail使用的端口  587     465
            client.Host = "XXXX";
            //client.ServicePoint.MaxIdleTime = 1;
            client.Credentials = new System.Net.NetworkCredential(username, password); //邮箱和密码
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true; //经过ssl加密

            try
            {
                client.Send(mail); 
            }
            catch (Exception ex)
            {
                throw new KDBusinessException("Error", ex.Message.ToString());
            }
图标赞 14
14人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!