コード例 #1
0
        public ActionResult SaveEmail(SupplierRequirementEmail email, string constractId, string attachs, string otherAttachs)
        {
            MasterService mstService = new MasterService();
            UserInfoDto   userinfo   = mstService.UserInfoSearchByUserId(UserInfo.UserId).FirstOrDefault();

            // 保存合同发送的信息
            service.ConstractEmailSendSave(constractId, UserInfo.UserId);

            //发送邮件
            string[] mailTo = email.Recipients.Split(',');
            string[] mailCC = new string[] { userinfo.Email };
            if (!string.IsNullOrEmpty(email.CCPerson))
            {
                mailCC = mailCC.Union(email.CCPerson.Split(',')).ToArray();
            }
            string subject = email.Title;
            string content = email.EmailContent == null ? "" : email.EmailContent.Replace("\n", "<br>");

            List <string> attachPaths = new List <string>();

            if (attachs != null)
            {
                foreach (string attach in attachs.Split(';'))
                {
                    attachPaths.Add(Server.MapPath("~/ConstractPdf/" + attach));
                }
            }
            if (otherAttachs != null)
            {
                foreach (string attach in otherAttachs.Split(';'))
                {
                    attachPaths.Add(Server.MapPath(EmailAttachs + attach));
                }
            }

            //个人签名 图片形式
            string sign = "";

            if (!string.IsNullOrEmpty(UserInfo.EmailFooter))
            {
                string emailSignFile = Server.MapPath("~/EmailSign/" + UserInfo.EmailFooter);
                sign = emailSignFile;
            }
            //准备发送邮件对象
            ISendMail sendMail = new UseNetMail();

            sendMail.CreateHost(new ConfigHost()
            {
                EnableSsl = false,
                Username  = userinfo.Email,
                Password  = userinfo.EmailPassword,
            });
            sendMail.CreateMultiMail(new ConfigMail()
            {
                From        = userinfo.Email,
                To          = mailTo,
                CC          = mailCC,
                Subject     = subject,
                Body        = content,
                Resources   = sign.Split(','),
                Attachments = attachPaths.ToArray()
            });

            sendMail.SendMail();

            return(Json(""));
        }
コード例 #2
0
        public ActionResult SaveEmail(SupplierRequirementEmail email, int SettlementId, string attachs, string otherAttachs)
        {
            MasterService mstService = new MasterService();
            UserInfoDto   userinfo   = mstService.UserInfoSearchByUserId(UserInfo.UserId).FirstOrDefault();

            var findOne = db.SettlementMst.Find(SettlementId);

            if (findOne != null)
            {
                findOne.EmailSendDateTime = DateTime.Now;
                findOne.EmailSendUser     = UserInfo.UserId;
            }
            db.SaveChanges();
            try
            {
                //发送邮件
                string[] mailTo = email.Recipients.Split(',');
                string[] mailCC = new string[] { userinfo.Email };
                if (!string.IsNullOrEmpty(email.CCPerson))
                {
                    mailCC = mailCC.Union(email.CCPerson.Split(',')).ToArray();
                }
                string subject = email.Title;
                string content = email.EmailContent == null ? "" : email.EmailContent.Replace("\n", "<br>");

                List <string> attachPaths = new List <string>();
                if (attachs != null)
                {
                    foreach (string attach in attachs.Split(';'))
                    {
                        attachPaths.Add(Server.MapPath("~/Export/Settlement/" + attach));
                    }
                    if (otherAttachs != null)
                    {
                        foreach (string attach in otherAttachs.Split(';'))
                        {
                            attachPaths.Add(Server.MapPath(EmailAttachs + attach));
                        }
                    }
                }

                //个人签名 图片形式
                string sign = "";
                if (!string.IsNullOrEmpty(UserInfo.EmailFooter))
                {
                    string emailSignFile = Server.MapPath("~/EmailSign/" + UserInfo.EmailFooter);
                    sign = emailSignFile;
                }
                //准备发送邮件对象
                ISendMail sendMail = new UseNetMail();
                sendMail.CreateHost(new ConfigHost()
                {
                    EnableSsl = false,
                    Username  = userinfo.Email,
                    Password  = userinfo.EmailPassword,
                });
                sendMail.CreateMultiMail(new ConfigMail()
                {
                    From        = userinfo.Email,
                    To          = mailTo,
                    CC          = mailCC,
                    Subject     = subject,
                    Body        = content,
                    Resources   = sign.Split(','),
                    Attachments = attachPaths.ToArray()
                });

                sendMail.SendMail();
            }
            catch (Exception)
            {
            }

            // 发完邮件之后保存供应商评分提醒
            try
            {
                MasterService master = new MasterService();
                master.RemindCancelSave("供应商评分填写提醒", findOne.ProjectId.ToString() + "&" + findOne.SupplierId.ToString(), UserInfo.UserId, DateTime.Now.ToString());
            }
            catch (Exception)
            {
            }


            return(Json(""));
        }