コード例 #1
0
ファイル: EmailService.cs プロジェクト: cliftonm/clifton
        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));
            }
        }
コード例 #2
0
ファイル: EmailService.cs プロジェクト: cliftonm/clifton
        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);
            }
        }
コード例 #3
0
        private Email CreateEmail()
        {
            Email email = new Email();
            IAppConfigService config = ServiceManager.Get<IAppConfigService>();
            email.AddTo(config.GetValue("emailExceptionTo"));
            email.Subject = config.GetValue("emailExceptionSubject");

            return email;
        }
コード例 #4
0
ファイル: EmailService.cs プロジェクト: cliftonm/clifton
 public void Process(ISemanticProcessor proc, IMembrane membrane, Email email)
 {
     proc.ServiceManager.Get<IEmailService>().Send(email);
 }