Esempio n. 1
0
        /// <summary>
        /// 发送服务邮件
        /// </summary>
        /// <param name="emailConfig"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private static async Task <Resp> SendAsync(EmailSmtpConfig emailConfig, EmailMsgMo msg)
        {
            var mm = new MailMessage
            {
                IsBodyHtml = true,
                Priority   = MailPriority.Normal,
                From       = new MailAddress(emailConfig.email, emailConfig.email_name, Encoding.UTF8),
                Subject    = msg.subject,
                Body       = msg.body
            };


            foreach (var mailItem in msg.to_emails)
            {
                mm.To.Add(new MailAddress(mailItem));
            }
            var client = new SmtpClient()
            {
                DeliveryMethod = SmtpDeliveryMethod.Network,
                EnableSsl      = emailConfig.enable_ssl > 0,
                Host           = emailConfig.host,
                Port           = emailConfig.port,
                Credentials    = new NetworkCredential(emailConfig.email, emailConfig.password)
            };

            using (client)
            {
                await client.SendMailAsync(mm);

                return(new Resp());
            }
        }
Esempio n. 2
0
 public Task <Resp> SetEmailConfig([FromBody] EmailSmtpConfig config)
 {
     if (config == null)
     {
         return(Task.FromResult(GetInvalidResp()));
     }
     return(_service.SetEmailConfig(config));
 }
Esempio n. 3
0
        /// <summary>
        /// 设置邮箱账号配置信息
        /// </summary>
        /// <returns></returns>
        public async Task <Resp> SetEmailConfig(EmailSmtpConfig config)
        {
            var res = await DirConfigHelper.SetDirConfig(CoreDirConfigKeys.plugs_notify_email_defult, config);

            return(res ? new Resp() : new Resp(RespTypes.OperateFailed, "设置华为云短信账号信息失败!"));
        }
Esempio n. 4
0
 public Mailer(IOptions <EmailSmtpConfig> smtpConfig, IWebHostEnvironment env)
 {
     this.smtpConfig = smtpConfig.Value;
     this.env        = env;
 }