Esempio n. 1
0
        protected override void OnExecute()
        {
            var configuration = settingPropertiesRepository.GetObject <SmtpConfiguration>(SettingPropertyKeys.SMTP_CONFIGURATION);

            if (configuration != null && !String.IsNullOrEmpty(configuration.SmtpHost) &&
                !String.IsNullOrEmpty(configuration.SmtpPasswordCipher) && !String.IsNullOrEmpty(configuration.SmtpUsername) &&
                configuration.SmtpPort > 0)
            {
                using (SmtpClient client = new SmtpClient(configuration.SmtpHost, configuration.SmtpPort))
                {
                    client.EnableSsl = true;
                    string password = Common.Cryptography.EncryptionSupport.Instance.Decrypt(configuration.SmtpPasswordCipher);
                    if (!String.IsNullOrEmpty(configuration.SmtpUsername) && !String.IsNullOrEmpty(password))
                    {
                        client.Credentials = new NetworkCredential(configuration.SmtpUsername, password);
                    }
                    else
                    {
                        client.Credentials = CredentialCache.DefaultNetworkCredentials;
                    }
                    using (var message = ConvertMessage(context.EmailDefinition, configuration.SystemEmailSender))
                    {
                        client.Send(message);
                        log.Write(SeverityType.Info, "Email with subject: {0} sent. (recipients: {1})",
                                  context.EmailDefinition.Subject, string.Join(",", context.EmailDefinition.Recipients));
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void OnExecute()
        {
            var reportingSettings = settingPropertiesRepository.GetObject <ReportingSettings>(SettingPropertyKeys.REPORTING_SETTINGS);
            var template          = settingPropertiesRepository.GetObject <EmailTemplate>(context.TemplateId);

            if (reportingSettings != null && reportingSettings.Recipients.Count > 0 && template != null)
            {
                context.EmailDefinition = new EmailDefinition()
                {
                    Body       = razorEngine.Transform(template.BodyTemplate, context.Model),
                    Recipients = reportingSettings.Recipients,
                    IsBodyHtml = template.IsBodyHtml,
                    Subject    = template.Subject
                };
            }
            else
            {
                IsEnabledSuccessorCall = false;
            }
        }