/// <summary> /// 使用系统邮件模块配置的信息,异步发送邮件(信息配置错误可能导致VS报错) /// </summary> public static MailState Send(MailInfo mailInfo) { MailConfig cfg = SiteConfig.MailConfig; SendHandler sender = null; if (cfg.Port == 25) { sender = SendEmail; } else if (cfg.Port == 465) { sender = SendSSLEmail; } else { throw new Exception("邮件端口[" + cfg.Port + "]配置不正确"); } if (string.IsNullOrEmpty(cfg.MailServerUserName)) { throw new Exception("未配置发送邮箱,取消发送"); } if (string.IsNullOrEmpty(cfg.MailServerPassWord)) { throw new Exception("未配置发送邮箱密码,取消发送"); } sender.BeginInvoke(cfg.MailServerUserName, cfg.MailServerPassWord, cfg.MailServer, mailInfo, "".Split(','), SendCallBack, null); return(MailState.Ok); }
/// <summary> /// 构造函数 /// </summary> public SiteConfigInfo() { if (this.m_MailConfig == null) { this.m_MailConfig = new MailConfig(); } if (this.m_IPLockConfig == null) { this.m_IPLockConfig = new IPLockConfig(); } if (this.m_UserConfig == null) { this.m_UserConfig = new UserConfig(); } if (this.m_ShopConfig == null) { this.m_ShopConfig = new ShopConfig(); } if (this.m_ThumbsConfig == null) { this.m_ThumbsConfig = new ThumbsConfig(); } if (this.m_WaterMarkConfig == null) { this.m_WaterMarkConfig = new WaterMarkConfig(); } if (this.m_SiteOption == null) { this.m_SiteOption = new SiteOption(); } if (this.m_SiteInfo == null) { this.m_SiteInfo = new SiteInfo(); } }
public SiteConfigInfo() { if (this.m_MailConfig == null) { this.m_MailConfig = new MailConfig(); } if (this.m_IPLockConfig == null) { this.m_IPLockConfig = new IPLockConfig(); } if (this.m_UserConfig == null) { this.m_UserConfig = new UserConfig(); } if (this.m_ShopConfig == null) { this.m_ShopConfig = new ShopConfig(); } if (this.m_ThumbsConfig == null) { this.m_ThumbsConfig = new ThumbsConfig(); } if (this.m_WaterMarkConfig == null) { this.m_WaterMarkConfig = new WaterMarkConfig(); } if (this.m_SiteOption == null) { this.m_SiteOption = new SiteOption(); } if (this.m_SiteInfo == null) { this.m_SiteInfo = new SiteInfo(); } }
private static MailMessage GetMailMessage(MailInfo mailInfo, MailConfig mailSettings) { MailMessage message = new MailMessage(); message.To.Add(mailInfo.ToAddress); if (mailInfo.ReplyTo != null) { message.ReplyTo = mailInfo.ReplyTo; } if (!string.IsNullOrEmpty(mailInfo.FromName)) { message.From = new MailAddress(mailSettings.MailFrom, mailInfo.FromName); } else { message.From = new MailAddress(mailSettings.MailFrom); } message.Subject = mailInfo.Subject; message.SubjectEncoding = Encoding.UTF8; message.Body = mailInfo.MailBody; message.BodyEncoding = Encoding.UTF8; message.Priority = mailInfo.Priority; message.IsBodyHtml = mailInfo.IsBodyHtml; return(message); }
private static MailState ValidInfo(MailInfo mailInfo, MailConfig mailSettings) { MailState none = MailState.None; if (string.IsNullOrEmpty(mailSettings.MailFrom) || string.IsNullOrEmpty(mailSettings.MailServer)) { return(MailState.MailConfigIsNullOrEmpty); } if (mailInfo.ToAddress == null) { return(MailState.NoMailToAddress); } if (string.IsNullOrEmpty(mailInfo.Subject)) { return(MailState.NoSubject); } return(none); }
private static MailState ValidInfo(MailInfo mailInfo, MailConfig mailSettings) { MailState none = MailState.None; if (string.IsNullOrEmpty(mailSettings.MailFrom) || string.IsNullOrEmpty(mailSettings.MailServer)) { return MailState.MailConfigIsNullOrEmpty; } if (mailInfo.ToAddress == null) { return MailState.NoMailToAddress; } if (string.IsNullOrEmpty(mailInfo.Subject)) { return MailState.NoSubject; } return none; }
private static MailMessage GetMailMessage(MailInfo mailInfo, MailConfig mailSettings) { MailMessage message = new MailMessage(); message.To.Add(mailInfo.ToAddress); if (mailInfo.ReplyTo != null) { message.ReplyTo = mailInfo.ReplyTo; } if (!string.IsNullOrEmpty(mailInfo.FromName)) { message.From = new MailAddress(mailSettings.MailFrom, mailInfo.FromName); } else { message.From = new MailAddress(mailSettings.MailFrom); } message.Subject = mailInfo.Subject; message.SubjectEncoding = Encoding.UTF8; message.Body = mailInfo.MailBody; message.BodyEncoding = Encoding.UTF8; message.Priority = mailInfo.Priority; message.IsBodyHtml = mailInfo.IsBodyHtml; return message; }
public static MailState Send(MailInfo mailInfo) { MailConfig mailConfig = SiteConfig.MailConfig; MailState mailcode = ValidInfo(mailInfo, mailConfig); if (mailcode == MailState.None) { SmtpClient client = new SmtpClient(); MailMessage mailMessage = GetMailMessage(mailInfo, mailConfig); try { try { client.Host = mailConfig.MailServer; client.Port = mailConfig.Port; NetworkCredential credential = new NetworkCredential(mailConfig.MailServerUserName, mailConfig.MailServerPassWord); string authenticationType = string.Empty; switch (mailConfig.AuthenticationType) { case AuthenticationType.None: client.UseDefaultCredentials = false; break; case AuthenticationType.Basic: client.UseDefaultCredentials = true; authenticationType = "Basic"; break; case AuthenticationType.Ntlm: authenticationType = "NTLM"; break; } client.EnableSsl = mailConfig.EnabledSsl; client.Credentials = credential.GetCredential(mailConfig.MailServer, mailConfig.Port, authenticationType); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Send(mailMessage); mailcode = MailState.Ok; } catch (SmtpException exception) { SmtpStatusCode statusCode = exception.StatusCode; if (statusCode != SmtpStatusCode.GeneralFailure) { if (statusCode == SmtpStatusCode.MustIssueStartTlsFirst) { goto Label_01D3; } if (statusCode == SmtpStatusCode.MailboxNameNotAllowed) { goto Label_01CE; } goto Label_01D8; } if (exception.InnerException is IOException) { mailcode = MailState.AttachmentSizeLimit; } else if (exception.InnerException is WebException) { if (exception.InnerException.InnerException == null) { mailcode = MailState.SmtpServerNotFind; } else if (exception.InnerException.InnerException is SocketException) { mailcode = MailState.PortError; } } else { mailcode = MailState.NonsupportSsl; } goto Label_01FA; Label_01CE: mailcode = MailState.UserNameOrPasswordError; goto Label_01FA; Label_01D3: mailcode = MailState.MustIssueStartTlsFirst; goto Label_01FA; Label_01D8: mailcode = MailState.SendFailure; } } finally { } } Label_01FA: mailInfo.Msg = GetMailStateInfo(mailcode); return(mailcode); }