Esempio n. 1
0
        public void Send(MailMessage msg, MailSenderConfiguration cfg)
        {
            var connectionString = cfg.BrokerConnectionString; //gen.EGenSettings.MQConnectionString;

            using (var bus = RabbitHutch.CreateBus(connectionString))
            {
                bus.Publish(msg);
            }
        }
Esempio n. 2
0
        //
        // ВНИМАНИЕ! SSL връзки на порт 465 не се поддържат нито от тази библиотека
        // нито от стандартната System.net.mail
        // защото не поддържат т.н. Implicit SSL.
        //

        public void  Send(MailMessage msg, MailSenderConfiguration cfg)
        {
            var readyMessage = msg.ToSystemNetMailMessage();

            using (var client = new System.Net.Mail.SmtpClient())
            {
                if (cfg != null)
                {
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new NetworkCredential(cfg.UserName, cfg.Password);
                    client.EnableSsl             = cfg.EnableSsl;
                    client.Host = cfg.Host;
                    client.Port = cfg.Port;
                }

                client.Send(readyMessage);
            }
        }
Esempio n. 3
0
        private MailSenderConfiguration createConfigurationFromAppSettings()
        {
            var retVal = new MailSenderConfiguration();

//            var config = ConfigurationSettings.GetConfig( .OpenExeConfiguration((ConfigurationUserLevel.None);

            var mailSettings = ConfigurationManager.GetSection("system.net/mailSettings/smtp")
                               as System.Net.Configuration.SmtpSection;

            if (mailSettings != null)
            {
                retVal.Host      = mailSettings.Network.Host;
                retVal.Port      = mailSettings.Network.Port;
                retVal.EnableSsl = mailSettings.Network.EnableSsl;
                retVal.UserName  = mailSettings.Network.UserName;
                retVal.Password  = mailSettings.Network.Password;
                retVal.HostName  = ConfigurationManager.AppSettings["HostName"] ?? "localhost";
            }
            return(retVal);
        }
Esempio n. 4
0
        public void Send(MailMessage msg, MailSenderConfiguration cfg)
        {
            var        realCfg = cfg ?? createConfigurationFromAppSettings();
            SmtpClient cl      = new SmtpClient();

            cl.ServerName       = realCfg.Host;
            cl.Port             = realCfg.Port;
            cl.AuthenticateMode = SmtpAuthenticateMode.Plain;
            //cl.Ssl = true;
            cl.Tls      = realCfg.EnableSsl;
            cl.UserName = realCfg.UserName;
            cl.Password = realCfg.Password;
            cl.HostName = realCfg.HostName;

            var mg = msg.ToSystemHigLaboSmtpMessage();

            var rs = cl.SendMail(mg); //

            if (rs.SendSuccessful == false)
            {
                // TODO - add error handling here!
                throw new Exception(String.Format("Error! Mail to {0} with subject = {1} was not sent! {2}", msg.To.ToString(), msg.Subject, rs.State.ToString()));
            }
        }
Esempio n. 5
0
 public MailSender(MailSenderConfiguration cfg, IMailSender sender = null, IMailLogger logger = null)
 {
     Sender        = sender ?? new NetSmtpMailSender();
     Logger        = logger ?? new MailLogger();
     Configuration = cfg;
 }