コード例 #1
0
        public JsonResult CallEmailService(SendEmailData email)
        {
            Common.Data.JsonData json = new Common.Data.JsonData()
            {
                Result = true
            };
            //查询邮件账户
            EmailSystemSetting setting = RefreshAppSetting.GetSystemEmailAccount();
            IEmailDataService  es      = IocMvcFactoryHelper.GetInterface <IEmailDataService>();

            es.LogPath = InitAppSetting.LogPath;
            AppEmailData data = new AppEmailData()
            {
                Body    = email.Body,
                From    = setting.EmailAccount,
                Mailer  = email.Mailer,
                To      = email.To,
                Subject = email.Subject
            };

            if (!string.IsNullOrEmpty(email.SendTime))
            {
                data.SendTime = Convert.ToDateTime(email.SendTime);
            }
            json.Success    = es.SendEmail(setting, data, setting.Smtp);
            json.AttachData = email;
            return(Json(json));
        }
コード例 #2
0
        public void LoopSendEmali(List <EmailAccount> accs, string subject)
        {//每日激活邮件账户
         //查询邮件账户列表
            string            dir          = LogPrepare.GetLogPath();
            ELogType          el           = ELogType.EmailLog;
            string            file         = LogPrepare.GetLogName(el);
            IEmailDataService emailService = IocMvcFactoryHelper.GetInterface <IEmailDataService>();

            foreach (var item in accs)
            {
                string time  = DateTime.Now.ToString(Common.Data.CommonFormat.DateTimeFormat);
                string title = "[HrApp Everyday active]";
                try
                {
                    //使用邮件账户进行邮件发送
                    short smtp = item.Smtp;
                    //拼接发送的邮件内容
                    EmailSystemSetting ess = new EmailSystemSetting()
                    {
                        EmailAccount      = item.Account,
                        EmailAuthortyCode = item.AuthortyCode,
                        EmailHost         = item.SmtpHost,
                        EmailHostPort     = EmailSystemSetting.GetHostPortSmtp(smtp)
                    };
                    ess.Smtp = (EnumSMTP)smtp;
                    StringBuilder body = new StringBuilder();
                    body.AppendLine(" Guid:<br/> ");
                    for (int i = 0; i < 10; i++)
                    {
                        body.AppendLine(string.Format(" {0}<br/> ", Guid.NewGuid().ToString().ToUpper()));
                    }
                    string       text      = string.Format("{0} <br/>  smtp= {1}<br/> time= {2} <br/>{3}  ", title, item.Account, time, body.ToString());
                    string       receive   = InitAppSetting.Global.ReceiverInEmailActive;
                    AppEmailData emailData = new AppEmailData()
                    {
                        EmailCreateTime = DateTime.Now,
                        To      = string.IsNullOrEmpty(receive) ? "*****@*****.**" : receive,
                        Subject = subject,
                        From    = item.Account,
                        Body    = text
                    };
                    emailService.SendEmail(ess, emailData, ess.Smtp);
                    LoggerWriter.CreateLogFile(title + "[Success]" + time, dir, el, file, true);
                }
                catch (Exception ex)
                {
                    title += ex.Message;
                    LoggerWriter.CreateLogFile(title + "[Error]" + time, dir, el, file, true);
                }
            }
        }
コード例 #3
0
        private void TestEmail(string title)
        {
            string text = "使用代码进行邮箱测试功能";
            string time = DateTime.Now.ToString(Common.Data.CommonFormat.DateTimeFormat);

            text += "<br/>邮件创建时间 :" + time;
            for (int i = 0; i < 10; i++)
            {
                text += string.Format("<br/> Guid{0}={1}", (i + 1), Guid.NewGuid().ToString().ToUpper());
            }
            string   logDir = LogPrepare.GetLogPath();
            ELogType el     = ELogType.EmailLog;
            string   day    = LogPrepare.GetLogName(el);

            try
            {
                Dictionary <string, string> emailSetting = InitAppSetting.AppSettingItemsInDB;
                string   type       = emailSetting[EAppSetting.SMTP.ToString()];
                string   sendBy     = emailSetting[EAppSetting.SystemEmailSendBy.ToString()];
                string   authorCode = emailSetting[EAppSetting.SystemEmailSMPTAuthor.ToString()];
                string   smtpClient = emailSetting[EAppSetting.SMTPClient.ToString()];
                EnumSMTP smtp;
                Enum.TryParse(type, out smtp);
                AppEmailData emailData = new AppEmailData()
                {
                    EmailCreateTime = DateTime.Now,
                    To      = InitAppSetting.Global.ReceiverInEmailActive,// "*****@*****.**",
                    Subject = title,
                    From    = sendBy,
                    Body    = text
                };
                EmailSystemSetting setting = new Model.EmailSystemSetting()
                {
                    EmailHostPort     = smtp == EnumSMTP.NETS163? 25:587,
                    EmailAuthortyCode = authorCode,
                    EmailAccount      = sendBy,
                    EmailHost         = smtpClient
                };

                #region 直接发送,不存储【测试可用】

                /*
                 * EmailData email = new EmailData()
                 * {
                 *  EmailTo =InitAppSetting.Global.ReceiverInEmailActive,
                 *  EmailSubject = title,
                 *  EmailBody = text,
                 *  CreateTime = DateTime.Now,
                 *  EmailFrom = sendBy
                 * };
                 * EmailService es = new EmailService(smtpClient, sendBy, authorCode, 25, true);
                 * es.SendEmailBy163(email);
                 * */
                #endregion
                IEmailDataService eds = IocMvcFactoryHelper.GetInterface <IEmailDataService>();
                eds.SendEmail(setting, emailData, smtp);
                LoggerWriter.CreateLogFile(time + "\t[OK]进行邮件测试", logDir, el, day, true);
            }
            catch (Exception ex)
            {
                string msg = time + "\t[ Error]" + ex.Message;
                LoggerWriter.CreateLogFile(msg, logDir, el, day, true);
            }
        }