private static MailMessage CreateMailMessage(EmailMessage emailMessage, IEmailSettings emailSettings) { var mailMessage = new MailMessage { Subject = emailMessage.Subject, Body = emailMessage.Message, ReplyToList = { emailSettings.FromEmailAddress }, From = new MailAddress(emailSettings.FromEmailAddress) }; SetAddresses(emailMessage.ToAddresses, mailMessage.To); SetAddresses(emailMessage.CcAddresses, mailMessage.CC); SetAddresses(emailMessage.BccAddresses, mailMessage.Bcc); var tempPath = Path.GetTempPath(); foreach (var attachedItem in emailMessage.AttachedItems) { var fileContent = attachedItem.Content as IFileContent; if (fileContent == null) { continue;//TODO - add error } var attachedFileInfo = fileContent.SaveToFile(tempPath); if (attachedFileInfo != null) { mailMessage.Attachments.Add(new Attachment(attachedFileInfo.FullName)); } } return(mailMessage); }
/// <summary> /// Configure the emailer - note that if config isn't valid this sill silently fail /// </summary> /// <param name="eSettings">Settings to use to configure error emailing</param> public static void Setup(IEmailSettings eSettings) { if (!eSettings.ToAddress.HasValue()) { Trace.WriteLine("Configuration invalid: ToAddress must have a value"); return; // not enabled } ToAddress = eSettings.ToAddress; if (eSettings.FromAddress.HasValue()) { FromAddress = eSettings.FromDisplayName.HasValue() ? new MailAddress(eSettings.FromAddress, eSettings.FromDisplayName) : new MailAddress(eSettings.FromAddress); } if (eSettings.SMTPUserName.HasValue() && eSettings.SMTPPassword.HasValue()) { Credentials = new NetworkCredential(eSettings.SMTPUserName, eSettings.SMTPPassword); } if (eSettings.SMTPHost.HasValue()) { Host = eSettings.SMTPHost; } if (eSettings.SMTPPort != 25) { Port = eSettings.SMTPPort; } EnableSSL = eSettings.SMTPEnableSSL; PreventDuplicates = eSettings.PreventDuplicates; Enabled = true; }
/// <summary> /// Configure the emailer - note that if config isn't valid this sill silently fail /// </summary> /// <param name="eSettings">Settings to use to configure error emailing</param> public static void Setup(IEmailSettings eSettings) { if (!eSettings.ToAddress.HasValue()) { Trace.WriteLine("Configuration invalid: ToAddress must have a value"); return; // not enabled } ToAddress = eSettings.ToAddress; if (eSettings.FromAddress.HasValue()) { FromAddress = eSettings.FromDisplayName.HasValue() ? new MailAddress(eSettings.FromAddress, eSettings.FromDisplayName) : new MailAddress(eSettings.FromAddress); } if (eSettings.SMTPUserName.HasValue() && eSettings.SMTPPassword.HasValue()) Credentials = new NetworkCredential(eSettings.SMTPUserName, eSettings.SMTPPassword); if (eSettings.SMTPHost.HasValue()) Host = eSettings.SMTPHost; if (eSettings.SMTPPort != 25) Port = eSettings.SMTPPort; EnableSSL = eSettings.SMTPEnableSSL; PreventDuplicates = eSettings.PreventDuplicates; Enabled = true; }
public AdminNotificationService(IEmailSettings emailSettings, IService <Database.Models.User> userService, IService <Organization> organizationService) : base(emailSettings) { _userService = userService; _organizationService = organizationService; }
/// <summary> /// Initializes a new instance of the <see cref="EmailSendRealizer"/> class. /// </summary> /// <param name="settings">Reference to class Settings. Refers to the data of the Settings class.</param> /// <param name="emailSender">>Reference to the class Sender. Refers the SendEmailAsync() method. Uses async/await.</param> /// <param name="watcher"> Reference to the WatcherWrapper class. The wraper of FileSystemWatcher class.</param> /// <param name="file">Reference to the FileWrapper class. The wrapper of File's parent class FileInfo.</param> public EmailSendRealizer(IEmailSettings settings, ISender emailSender, IWatcher watcher, IFileWrapper file) { this._settings = settings; this._emailSender = emailSender; this._watcher = watcher; this._file = file; }
/// <summary> /// Create instance of EmailService with specified providers /// </summary> /// <param name="mailProvider"></param> /// <param name="templateProvider"></param> /// <param name="emailTemplateConfiguration"></param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="EmailSettingsException"></exception> public EmailService(IMailProvider mailProvider, IMessageTemplateProvider templateProvider, IEmailTemplateConfiguration emailTemplateConfiguration) { _log = LogManager.GetLogger(GetType()); if (mailProvider == null) { throw new ArgumentNullException(nameof(mailProvider)); } if (emailTemplateConfiguration == null) { throw new ArgumentNullException(nameof(emailTemplateConfiguration)); } _emailSettings = new Settings().EmailSettings; if (_emailSettings == null) { throw new EmailSettingsException(); } _mailProvider = mailProvider; _templateProvider = templateProvider; _emailTemplateConfiguration = emailTemplateConfiguration; _engineService = RazorEngineService.Create((ITemplateServiceConfiguration)_emailTemplateConfiguration); }
public ShedulerService(IEmailService emailService, IFormMessageService formMessageService, IEmailSettings emailSettings, IMessage message, ISiteSettings siteSettings) { _emailService = emailService; _formMessageService = formMessageService; _emailSettings = emailSettings; _siteSettings = siteSettings; _message = message; }
public ShareAdminTests() { _emailSettings = new EmailSettings { LocalDirectoryPath = "C:\\temp", Sender = "*****@*****.**", Subject = "Hey see my questions!" }; }
/// <summary> /// Initializes a new instance of the <see cref="EmailSender"/> class. /// </summary> /// <param name="unitOfWork">Unit of work.</param> /// <param name="eventAggregator">Event aggregator.</param> /// <param name="resourceHandler">Resource handler.</param> /// <param name="settings">E-mail settings.</param> public EmailSender( IUnitOfWork unitOfWork, IEventAggregator eventAggregator, IResourceHandler resourceHandler, IEmailSettings settings) { this.unitOfWork = unitOfWork; this.eventAggregator = eventAggregator; this.resourceHandler = resourceHandler; this.settings = settings; }
public async Task Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; _emailService = (IEmailService)dataMap["emailService"]; _formMessageService = (IFormMessageService)dataMap["formMessageService"]; _emailSettings = (IEmailSettings)dataMap["emailSettings"]; _message = (IMessage)dataMap["message"]; _siteSettings = (ISiteSettings)dataMap["siteSettings"]; await _emailService.SendEmailAsync(_formMessageService, _emailSettings, _message, _siteSettings); }
public EmailNotificationService(IEmailSettings emailSettings, IAdminNotificationService adminNotificationService, IUserNotificationService userNotificationService, ILegalOfficerNotificationService legalOfficerNotificationService, IConsumerProviderRegistrationNotificatonService consumerProviderRegistrationNotificationService) : base(emailSettings) { Admin = adminNotificationService; User = userNotificationService; LegalOfficer = legalOfficerNotificationService; ConsumerProviderRegistration = consumerProviderRegistrationNotificationService; }
public Sender(IEmailSettings emailSettings) { this._emailSettings = emailSettings; this._client = new SmtpClient(this._emailSettings.Host); this._mailMessage = new MailMessage(this._emailSettings.FromAddress, this._emailSettings.ToAddress) { BodyEncoding = Encoding.UTF8, Subject = this._emailSettings.Subject, Body = this._emailSettings.MailBody }; }
public static void BootstrapForTests( ISystemLog systemLog, IOfficeLocationDatabaseSettings officeLocationDatabaseSettings, ICountryWebApiSettings countryWebApiSettings, IEmailSettings emailSettings, IGroupNameConstants groupNameConstants) { BootstrapAll(systemLog, officeLocationDatabaseSettings, countryWebApiSettings, emailSettings, groupNameConstants); }
public UserNotificationService(IService <Database.Models.User> userService, IService <LicenseClauseTemplate> clausesTemplateService, IService <OrganizationLicense> licenseService, IService <Application> appService, IService <Organization> organizationService, IService <DataSchema> dataSchemaService, IEmailSettings emailSettings) : base(emailSettings) { _userService = userService; _clausesTemplateService = clausesTemplateService; _licenseService = licenseService; _appService = appService; _organizationService = organizationService; _dataSchemaService = dataSchemaService; }
/// <summary> /// Initializes a new instance of the <see cref="EmailService"/> class. /// </summary> public EmailService() { _config = new EmailServiceSettings(); this._config.AuthenticationPassword = ConfigurationSettings.AppSettings["SMTPAuthenticationPassword"].ToString(); this._config.AuthenticationUserName = ConfigurationSettings.AppSettings["SMTPAuthenticationUserName"].ToString(); this._config.SmptServer = ConfigurationSettings.AppSettings["SmtpServer"].ToString(); this._config.Port = Convert.ToInt16(ConfigurationSettings.AppSettings["SmtpPort"]); this._config.EnableSSL = ConfigurationSettings.AppSettings["EnableSSL"].ToString(); this._config.UseDefaultCredentials = ConfigurationSettings.AppSettings["UseDefaultCredentials"].ToString(); if (ConfigurationSettings.AppSettings["SmtpPort"].ToString() == "") { this._config.UsePort = false; } this._config.IsAuthenticationRequired = true; }
private static void BootstrapAll( ISystemLog logForNetSystemLog, IOfficeLocationDatabaseSettings officeLocationDatabaseSettings, ICountryWebApiSettings countryWebApiSettings, IEmailSettings emailSettings, IGroupNameConstants groupNameConstants) { var webServiceCaller = new WebApiServiceCaller(logForNetSystemLog); MasterFactory.OfficeDataTableGateway = new OfficeDataTableGateway(officeLocationDatabaseSettings, logForNetSystemLog); MasterFactory.CountryWebApiGateway = new CountryWebApiGateway(countryWebApiSettings, webServiceCaller); MasterFactory.EmailClient = new EmailClient(emailSettings); MasterFactory.GroupNameConstants = groupNameConstants; }
public BaseEmailService(IEmailSettings emailSettings) { _emailSettings = emailSettings; var viewEngines = new ViewEngineCollection(); var viewsPath = Path.Combine(ConfigurationManager.AppSettings["PathToEmailViews"]); viewEngines.Add(new FileRazorViewEngine(viewsPath)); _emailService = new EmailService(viewEngines, BuildSmtpClient); _emailDumpPath = $"{AppDomain.CurrentDomain.BaseDirectory}{emailSettings.PathToMail}"; Directory.CreateDirectory(_emailDumpPath); // todo : move all configuration to a ninject // todo: move to config DataLinkerHost = ConfigurationManager.AppSettings["DataLinkerHost"]; UrlToCssFile = ConfigurationManager.AppSettings["UrlToCSSEmail"]; UrlForImageInEmail = ConfigurationManager.AppSettings["UrlToImageInEmail"]; DataLinkerContactEmail = ConfigurationManager.AppSettings["DataLinkerContactEmail"]; }
public static void BootstrapForSystem( string logName, IOfficeLocationDatabaseSettings officeLocationDatabaseSettings, ICountryWebApiSettings countryWebApiSettings, IEmailSettings emailSettings, IGroupNameConstants groupNameConstants) { LoggingBootstrapper.StartupLog(logName); var logForNetSystemLog = new LogForNetSystemLog(); BootstrapAll(logForNetSystemLog, officeLocationDatabaseSettings, countryWebApiSettings, emailSettings, groupNameConstants); }
internal static EmailItems ToEmailItems(IEmailSettings settings, EmailType type, IEnumerable <string> to, IEnumerable <string> cc, string subject, string content) { var email = new EmailItems { // "From" comes directly from settings (no validation) FromName = settings.FromName, FromEmail = settings.FromEmail, // "To" is possibly set by the "Type" (or by what was passed in) To = (type switch { EmailType.Exception => settings.ExceptionsRecipients, EmailType.HiddenException => settings.HiddenExceptionRecipients, EmailType.Logging => settings.LoggingRecipients, EmailType.LongRunning => settings.LongRunningRecipients, EmailType.HttpFailure => settings.HttpFailureRecipients, EmailType.Custom => to, _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) }).ToList()
/// <summary> /// Create instance of EmailService with specified providers /// </summary> /// <param name="logger"></param> /// <param name="configuration"></param> /// <param name="mailProvider"></param> /// <param name="templateProvider"></param> /// <param name="emailTemplateConfiguration"></param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="EmailSettingsException"></exception> public EmailService(ILogger <EmailService> logger, IConfiguration configuration, IMailProvider mailProvider, IMessageTemplateProvider templateProvider, IEmailTemplateConfiguration emailTemplateConfiguration, IMessageProvider messageProvider) { _logger = logger; _configuration = configuration; var section = _configuration.GetSection("gaia:emailSettings"); //if (section?.Value == null) //{ // throw new EmailSettingsException(); //} _emailSettings = new EmailSettings(); section.Bind(_emailSettings); _mailProvider = mailProvider ?? throw new ArgumentNullException(nameof(mailProvider)); _templateProvider = templateProvider ?? throw new ArgumentNullException(nameof(templateProvider)); _emailTemplateConfiguration = emailTemplateConfiguration ?? throw new ArgumentNullException(nameof(emailTemplateConfiguration)); _messageProvider = messageProvider ?? throw new ArgumentNullException(nameof(messageProvider)); }
public ConsumerProviderRegistrationNotificationService(IEmailSettings emailSettings, IService <OrganizationLicense> licenseService, IService <Application> applicationService, IService <Organization> organizationService, IService <LicenseTemplate> licenseTemplateService, ILicenseContentBuilder licenseContentBuilder, IService <Database.Models.User> userService, IService <LicenseAgreement> agreementService, IService <ConsumerProviderRegistration, int> consumerProviderRegistration, IService <DataSchema> dataSchemaService, ILicenseFileProvider licenseFileProvider) : base(emailSettings) { _licenseService = licenseService; _applicationService = applicationService; _organizationService = organizationService; _licenseTemplateService = licenseTemplateService; _licenseContentBuilder = licenseContentBuilder; _userService = userService; _agreementService = agreementService; _consumerProviderRegistrations = consumerProviderRegistration; _dataSchemaService = dataSchemaService; _licenseFileProvider = licenseFileProvider; }
public async Task SendEmailAsync(IFormMessageService formMessageService, IEmailSettings emailSettings, IMessage message, ISiteSettings siteSettings) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress(message.SenderName, message.SenderEmail)); emailMessage.To.Add(new MailboxAddress("", message.RecieverEmail)); emailMessage.Subject = message.MessageSubject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message.MessageBody + Environment.NewLine + formMessageService.GetMessage(siteSettings) }; using (var client = new SmtpClient()) { await client.ConnectAsync(emailSettings.Host, emailSettings.Port, emailSettings.EnableSSL); await client.AuthenticateAsync(emailSettings.UserEmail, emailSettings.UserPassword); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public EmailTarget(IEmailSettings settings) { _settings = settings; }
/// <summary> /// Initialize the configuration. /// </summary> /// <param name="config"></param> public void Init(IEmailSettings config) { _config = config; }
public EmailClient(IEmailSettings emailSettings) => _emailSettings = emailSettings;
public MimeKitEmailSender(ISmtpSettings settings, IEmailSettings emailSettings) { _settings = settings; _emailSettings = emailSettings; }
public WecEmailClient(IEmailSettings settings) { _settings = settings; }
public EmailNotificationService(IEmailSettings emailSettings) { this.emailSettings = emailSettings; }
public SmtpProvider(IEmailSettings settings) { _settings = settings; }
/// <summary> /// Initializes a new instance of the <see cref="EmailService"/> class. /// </summary> /// <param name="settings">The config.</param> public EmailService(IEmailSettings settings) { Init(settings); }
public EmailSender(IEmailSettings settings) { m_settings = settings; }
public EmailService(IEmailSettings settings) { _settings = settings; }
public EmailSender(IEmailSettings emailSettings) { _emailSettings = emailSettings; }
public EmailNotifier(IEmailSettings settings, ISmtpProvider smtpProvider, ILogger logger) { _settings = settings; _smtpProvider = smtpProvider; _logger = logger; }
public EmailService( IEmailSettings emailSettings) { _emailSettings = emailSettings; }