Exemple #1
0
        public void Send(Email email)
        {
            IConfigService config = ServiceManager.Get<IConfigService>();

            try
            {
                // TODO: Until we figure out why we can't send emails from bmbfc.org, we're using our poloron server.
                string username = config.GetValue("emailusername");
                string password = config.GetValue("emailpassword");
                string fromEmail = email.From ?? config.GetValue("emailfrom"); //  "*****@*****.**";
                string host = config.GetValue("emailhost");

                SmtpClient smtpClient = new SmtpClient();
                NetworkCredential basicCredential = new NetworkCredential(username, password);
                MailMessage message = new MailMessage();
                MailAddress fromAddress = new MailAddress(fromEmail);

                smtpClient.Host = host;
                smtpClient.Port = 587;          // Note the port setting!
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = basicCredential;

                message.From = fromAddress;
                message.Subject = email.Subject;
                message.IsBodyHtml = true;
                message.Body = email.Body;
                message.IsBodyHtml = true;
                // message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(email.Body, null, MediaTypeNames.Text.Html));

                email.To.ForEach(e => message.To.Add(e));
                email.Cc.IfNotNull(ccs => ccs.ForEach(cc => message.CC.Add(cc)));
                email.Bcc.IfNotNull(bccs => bccs.ForEach(bcc => message.Bcc.Add(bcc)));

                smtpClient.Send(message);
            }
            catch (Exception ex)
            {
                // If an exception occurs when emailing, log through whatever logging mechanism in place, rather than handling by trying to email another exception!
                Assert.SilentTry(() =>
                    ServiceManager.Get<ISemanticProcessor>().ProcessInstance<LoggerMembrane, ST_Exception>(ex2 => ex2.Exception = ex, true));
            }
        }
Exemple #2
0
        public virtual void Send(Email email)
        {
            IConfigService config = ServiceManager.Get<IConfigService>();

            try
            {
                // TODO: Until we figure out why we can't send emails from bmbfc.org, we're using our poloron server.
                string username = config.GetValue("emailusername");
                string password = config.GetValue("emailpassword");
                string fromEmail = email.From ?? config.GetValue("emailfrom"); //  "*****@*****.**";
                string host = config.GetValue("emailhost");

                SmtpClient smtpClient = new SmtpClient();
                NetworkCredential basicCredential = new NetworkCredential(username, password);
                MailMessage message = new MailMessage();
                MailAddress fromAddress = new MailAddress(fromEmail);

                smtpClient.Host = host;
                smtpClient.Port = 587;          // Note the port setting!
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = basicCredential;

                message.From = fromAddress;
                message.Subject = email.Subject;
                message.IsBodyHtml = true;
                message.Body = email.Body;
                message.IsBodyHtml = true;

                email.To.ForEach(e => message.To.Add(e));
                email.Cc.IfNotNull(ccs => ccs.ForEach(cc => message.CC.Add(cc)));
                email.Bcc.IfNotNull(bccs => bccs.ForEach(bcc => message.Bcc.Add(bcc)));

                smtpClient.Send(message);
            }
            catch (Exception ex)
            {
                ServiceManager.Get<ILoggerService>().Log(ex);
            }
        }
        private Email CreateEmail()
        {
            Email email = new Email();
            IAppConfigService config = ServiceManager.Get<IAppConfigService>();
            email.AddTo(config.GetValue("emailExceptionTo"));
            email.Subject = config.GetValue("emailExceptionSubject");

            return email;
        }
Exemple #4
0
 public void Process(ISemanticProcessor proc, IMembrane membrane, Email email)
 {
     proc.ServiceManager.Get<IEmailService>().Send(email);
 }