private void SaveEmailInfo_Click(object sender, EventArgs e) { #region 保存邮箱设置 if (this.CheckCookie()) { EmailConfigInfo __emailinfo = EmailConfigs.GetConfig(); __emailinfo.Smtp = smtp.Text; __emailinfo.Port = Convert.ToInt32(port.Text); __emailinfo.Sysemail = sysemail.Text; __emailinfo.Username = userName.Text; __emailinfo.Password = password.Text; try { __emailinfo.PluginNameSpace = smtpemail.SelectedValue.Split(',')[0]; __emailinfo.DllFileName = smtpemail.SelectedValue.Split(',')[1]; } catch { ; } EmailConfigs.SaveConfig(__emailinfo); Emails.ReSetISmtpMail(); base.RegisterStartupScript("PAGE", "window.location.href='global_emailconfig.aspx';"); } #endregion }
// Token: 0x06000023 RID: 35 RVA: 0x00003F54 File Offset: 0x00002154 protected override void View() { this.emailconfig = EmailConfigs.GetEmailConfig(); if (this.ispost) { if (this.action == "save") { this.emailconfig.ssl = 0; this.emailconfig = FPRequest.GetModel <EmailConfig>(this.emailconfig); EmailConfigs.SaveConfig(this.emailconfig); Email.ReSetConfig(); base.AddMsg("保存配置成功!"); } else if (this.action == "send") { this.testmail = FPRequest.GetString("testmail"); if (this.testmail == "") { this.ShowErr("请输入测试发送EMAIL地址!"); return; } string text = Email.Send(this.testmail, "方配网站管理系统(WMS)发送系统测试邮件", "您好,这是一封方配网站管理系统(WMS)邮箱设置页面发送的测试邮件!,如果您收到这款邮件说明您的邮箱配置是正确的。"); if (!(text == "")) { this.ShowErr(text); return; } base.AddMsg("发布测试邮件成功,请检查是否收到。"); } } base.SaveRightURL(); }
public EmailService( IOptions <EmailConfigs> emailConfigs, IOptions <TokenConfig> tokenConfig, UserManager <ApplicationUser> userManager ) { _emailConfigs = emailConfigs.Value; _tokenConfig = tokenConfig.Value; _userManager = userManager; }
public IdentitiesController ( IOptions <EmailConfigs> emailConfigs, IOptions <GoogleReCaptchaConfigs> googleReCaptchaConfigs, IIdentityService identityService, IEmailService emailService, ILogger <IdentitiesController> logger, IUrlHelper urlHelper ) : base(logger, urlHelper) { _emailConfigs = emailConfigs.Value; _googleReCaptchaConfigs = googleReCaptchaConfigs.Value; _identityService = identityService; _emailService = emailService; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { EmailConfigInfo __emailinfo = EmailConfigs.GetConfig(); GeneralConfigInfo configinfo = GeneralConfigs.GetConfig(); string strbody = __emailinfo.Emailcontent.Replace("{forumtitle}", configinfo.Forumtitle); strbody = strbody.Replace("{forumurl}", "<a href=" + configinfo.Forumurl + ">" + configinfo.Forumurl + "</a>"); strbody = strbody.Replace("{webtitle}", configinfo.Webtitle); strbody = strbody.Replace("{weburl}", "<a href=" + configinfo.Forumurl + ">" + configinfo.Weburl + "</a>"); body.Text = strbody; } if (DNTRequest.GetString("flag") == "1") { this.ExportUserEmails(); } }
public ReturnData Send(EmailMessage emailMessage, EmailConfigs emailConfigs) { try { var message = new MimeMessage(); message.To.AddRange(emailMessage.ToAddresses.Select(x => new MailboxAddress(x.Name, x.Address))); message.From.AddRange(emailMessage.FromAddresses.Select(x => new MailboxAddress(x.Name, x.Address))); message.Subject = emailMessage.Subject; var builder = new BodyBuilder(); //var image = builder.LinkedResources.Add(emailMessage.InstitutionLogo); //image.ContentId = "logoId"; builder.HtmlBody = emailMessage.Content; message.Body = builder.ToMessageBody(); var smtpPort = Int32.Parse(emailConfigs.Port); var options = smtpPort == 587 ? SecureSocketOptions.None : SecureSocketOptions.SslOnConnect; using (var emailClient = new SmtpClient()) { emailClient.Connect(emailConfigs.SmtpClient, smtpPort, options); emailClient.AuthenticationMechanisms.Remove("XOAUTH2"); //Remove any OAuth functionality as we won't be using it. emailClient.Authenticate(emailConfigs.EmailUserName, emailConfigs.Password); emailClient.Send(message); emailClient.Disconnect(true); } return(new ReturnData { Success = true, Message = "Kindly check your email to activate your account" }); } catch (Exception ex) { return(new ReturnData { Success = false, Message = "An error occured while sending an email, Kindly reset your password later" }); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { EmailConfigInfo emailInfo = EmailConfigs.GetConfig(); smtp.Text = emailInfo.Smtp; port.Text = emailInfo.Port.ToString(); sysemail.Text = emailInfo.Sysemail; userName.Text = emailInfo.Username; password.Text = emailInfo.Password; try { GetSmtpEmailPlugIn(HttpRuntime.BinDirectory); } catch { smtpemail.Items.Clear(); try { GetSmtpEmailPlugIn(Utils.GetMapPath("/bin/")); } catch { smtpemail.Items.Add(new ListItem(".net邮件发送程序", "Discuz.Common.SysMailMessage,Discuz.Common")); smtpemail.Items.Add(new ListItem("Discuz!NT邮件发送程序", "Discuz.Common.SmtpMail,Discuz.Common")); } } try { smtpemail.SelectedValue = emailInfo.PluginNameSpace + "," + emailInfo.DllFileName; } catch { ;// smtpemail.SelectedIndex = 1; } } }
//重设置当前邮件发送类的实例对象 public static void ReSetISmtpMail() { try { emailinfo = EmailConfigs.GetConfig(); //读取相应的DLL信息 Assembly asm = Assembly.LoadFrom(HttpRuntime.BinDirectory + emailinfo.DllFileName); ESM = (ISmtpMail)Activator.CreateInstance(asm.GetType(emailinfo.PluginNameSpace, false, true)); } catch { try { //读取相应的DLL信息 Assembly asm = Assembly.LoadFrom(Utils.GetMapPath("/bin/" + emailinfo.DllFileName)); ESM = (ISmtpMail)Activator.CreateInstance(asm.GetType(emailinfo.PluginNameSpace, false, true)); } catch { ESM = new SmtpMail(); } } }
//重设置当前邮件发送类的实例对象 public static void ReSetISmtpMail() { emailinfo = EmailConfigs.GetConfig(); LoadEmailPlugin(); }
/// <summary> /// 邮件发送 /// </summary> /// <param name="emailType">邮件类型</param> /// <param name="emailTo">收件人的电子邮件地址。使用分号 (;) 分隔多名收件人。</param> /// <param name="emailTitle">电子邮件的主题行。</param> /// <param name="emailContent">电子邮件的正文。如果 isBodyHtml 为 true,则将正文中的 HTML 解释为标记。</param> /// <param name="filePath">(可选)文件名的集合,用于指定要附加到电子邮件中的文件;如果没有要附加的文件,则为 null。默认值为 null。</param> /// <param name="additionalHeaders">(可选)标头的集合,可添加到此电子邮件包含的正常 SMTP 标头中;如果不发送其他标头,则为 null。默认值为 null。</param> /// <param name="CC">邮件抄送人</param> public static bool SendMail(EmailTypeEnum emailType, string emailTo, string emailTitle, string emailContent, IEnumerable <string> filePath = null, IEnumerable <string> additionalHeaders = null, string CC = "") { if (string.IsNullOrEmpty(emailTitle)) { ErrorLog("暂无标题", "标题不能为空"); return(false); } if (string.IsNullOrEmpty(emailContent)) { ErrorLog(emailTitle, "邮件内容不能为空"); return(false); } var config = EmailConfigs.FirstOrDefault(s => s.ConfigName == emailType.ToString()); if (config == null) { ErrorLog(emailTitle, "无法获取有效的邮件配置信息"); return(false); } var smtp = new SmtpClient { UseDefaultCredentials = true, Credentials = new NetworkCredential(config.UserName, config.Password), DeliveryMethod = SmtpDeliveryMethod.Network, Port = config.Port, Host = config.Host, EnableSsl = true }; var mail = new MailMessage { From = new MailAddress(config.From) }; if (!string.IsNullOrEmpty(emailTo)) { emailTo = emailTo.Replace(";", ";").Trim(';'); foreach (var mailTo in emailTo.Split(';')) { if (RegEmail(mailTo)) { mail.To.Add(new MailAddress(mailTo)); } } } if (!string.IsNullOrEmpty(CC)) { CC = CC.Replace(";", ";").Trim(';'); foreach (var item in CC.Split(';')) { if (RegEmail(item)) { mail.CC.Add(new MailAddress(item)); } } } if (mail.To.Count == 0 && mail.CC.Count == 0) { ErrorLog(emailTitle, "收件人和抄送人不能同时为空"); return(false); } mail.Subject = emailTitle; mail.Body = emailContent; mail.IsBodyHtml = true; if (filePath != null) { foreach (var item in filePath) { if (Directory.Exists(item)) { mail.Attachments.Add(new Attachment(item)); } } } if (additionalHeaders != null) { foreach (var item in additionalHeaders) { try { mail.Headers.Add(null, item); } catch (Exception ex) { } } } try { smtp.Send(mail); } catch (Exception ex) { ErrorLog(emailTitle, ex.Message); return(false); } #region 发送邮件日志 Log(emailTo, emailTitle, CC, config); #endregion return(true); }