Exemplo n.º 1
0
        internal static SmtpServer GetSMTP(int ModuleId, string Identifier)
        {
            SmtpServer smtp = new SmtpServer();

            CacheFactory.ClearCache();
            List <Setting> SmtpSettings = SettingFactory.GetSettings(ModuleId, Identifier);
            string         Server = string.Empty, Port = string.Empty, Authentication = string.Empty, Username = string.Empty, Password = string.Empty, SSL = string.Empty;

            if (SmtpSettings.Count > 0)
            {
                string dnnhostsettings = SmtpSettings.Where(s => s.Name == "DNNHostSetting").FirstOrDefault().Value;
                if (dnnhostsettings.ToLower() == "false")
                {
                    Server = SmtpSettings.Where(s => s.Name == "Server").FirstOrDefault().Value;
                    if (!string.IsNullOrEmpty(Server))
                    {
                        smtp.Server = Server;
                    }

                    Port = SmtpSettings.Where(s => s.Name == "Port").FirstOrDefault().Value;
                    if (Port != null && int.Parse(Port) > -1)
                    {
                        smtp.Port = int.Parse(Port);
                    }

                    Authentication = SmtpSettings.Where(s => s.Name == "Authentication").FirstOrDefault().Value;
                    if (!string.IsNullOrEmpty(Authentication))
                    {
                        smtp.Authentication = Authentication;
                    }

                    Username = SmtpSettings.Where(s => s.Name == "Username").FirstOrDefault().Value;
                    if (!string.IsNullOrEmpty(Username))
                    {
                        smtp.Username = Username;
                    }

                    Password = SmtpSettings.Where(s => s.Name == "Password").FirstOrDefault().Value;
                    if (!string.IsNullOrEmpty(Password))
                    {
                        smtp.Password = Password;
                    }

                    SSL = SmtpSettings.Where(s => s.Name == "SSL").FirstOrDefault().Value;
                    if (!string.IsNullOrEmpty(SSL))
                    {
                        smtp.SSL = Convert.ToBoolean(SSL);
                    }
                }
                else
                {
                    smtp = GetDNNHostSettingsSmtpServer(ModuleId);
                }
            }
            return(smtp);
        }
Exemplo n.º 2
0
        private static MailQueue ProcessMailQueue(int ModuleID, string Subject, string Content, string ToEmail, List <Data.Entities.Attachment> Attachments, string FromName, string FromEmail, string FromEmailPrefix, string ReplyEmail)
        {
            MailQueue mailQueue = null;

            if (!string.IsNullOrEmpty(Subject) && !string.IsNullOrEmpty(Content) && !string.IsNullOrEmpty(ToEmail))
            {
                mailQueue = new MailQueue
                {
                    ModuleID      = ModuleID,
                    Subject       = Subject,
                    Content       = Content,
                    SmtpUniqueId  = -1,
                    Status        = "Queue",
                    RetryAttempt  = 0,
                    RetryDateTime = DateTime.UtcNow
                };

                List <Setting> Settings = SettingFactory.GetSettings(ModuleID, AppFactory.Identifiers.admin_notifications_email.ToString());

                if (Settings.Count > 0)
                {
                    try
                    {
                        if (Settings.Where(s => s.Name == "DNNHostSetting").FirstOrDefault() != null && Settings.Where(s => s.Name == "DNNHostSetting").FirstOrDefault().Value.ToLower() == "false")
                        {
                            if (Settings.Where(s => s.Name == "ReplyFromDisplayName").FirstOrDefault() != null)
                            {
                                mailQueue.FromName = Settings.Where(s => s.Name == "ReplyFromDisplayName").FirstOrDefault().Value;
                            }

                            if (Settings.Where(s => s.Name == "ReplyFromEmail").FirstOrDefault() != null)
                            {
                                mailQueue.FromEmail = Settings.Where(s => s.Name == "ReplyFromEmail").FirstOrDefault().Value;
                            }

                            if (Settings.Where(s => s.Name == "ReplyTo").FirstOrDefault() != null)
                            {
                                mailQueue.ReplyEmail = Settings.Where(s => s.Name == "ReplyTo").FirstOrDefault().Value;
                            }
                        }
                        else
                        {
                            mailQueue.FromName   = Host.HostEmail;
                            mailQueue.FromEmail  = Host.HostEmail;
                            mailQueue.ReplyEmail = Host.HostEmail;
                        }
                    }
                    catch { }
                }

                if (!string.IsNullOrEmpty(FromName))
                {
                    mailQueue.FromName = FromName;
                }

                if (!string.IsNullOrEmpty(FromEmail))
                {
                    mailQueue.FromEmail = FromEmail;
                }

                if (!string.IsNullOrEmpty(ReplyEmail))
                {
                    mailQueue.ReplyEmail = ReplyEmail;
                }

                if (string.IsNullOrEmpty(mailQueue.ReplyEmail))
                {
                    mailQueue.ReplyEmail = mailQueue.FromEmail;
                }

                mailQueue.ToEmail = ToEmail;

                if (Attachments != null && Attachments.Count > 0)
                {
                    mailQueue.Attachment = Newtonsoft.Json.JsonConvert.SerializeObject(Attachments);
                }
                else
                {
                    mailQueue.Attachment = "";
                }

                //Fix for 50310 and 50294  auto-no-reply-helpdesk@
                if (!string.IsNullOrEmpty(FromEmailPrefix) && !string.IsNullOrEmpty(mailQueue.FromEmail))
                {
                    mailQueue.FromEmail = FromEmailPrefix + mailQueue.FromEmail.Split('@')[1];
                }
            }

            return(mailQueue);
        }