static public IEmailSmtpSettings GetSmtpSettingsFromCompany(CompanyDTO company) { var settings = new EmailSmtpSettings(); if (company == null) { return(settings); } var smtpSettings = company.EmailAccounts.FirstOrDefault(e => e.Type == (int)EmailAccountType.Smtp); if (smtpSettings == null) { return(settings); } settings.SmtpHost = smtpSettings.ServerHost; settings.SmtpPort = smtpSettings.ServerPort; settings.SmtpUsername = smtpSettings.UserName; settings.SmtpPassword = smtpSettings.Password; settings.SmtpFromEmail = smtpSettings.FromEmail; settings.SmtpFromDisplayName = smtpSettings.DisplayName; settings.IsDebug = AppSettings.IsDebug; return(settings); }
public static IEmailSmtpSettings GetSmtpSettingsFromCompany(CompanyDTO company, bool isDebug, bool isSampleMode) { var emailAccount = company.EmailAccounts.FirstOrDefault(a => a.Type == (int)EmailAccountType.Smtp); if (emailAccount == null) { return(null); } var settings = new EmailSmtpSettings(); settings.SystemEmailPrefix = company.CompanyName; settings.SmtpHost = emailAccount.ServerHost; settings.SmtpPort = emailAccount.ServerPort; settings.SmtpUsername = emailAccount.UserName; settings.SmtpPassword = emailAccount.Password; settings.SmtpFromEmail = emailAccount.FromEmail; settings.SmtpFromDisplayName = emailAccount.DisplayName; settings.IsDebug = isDebug; settings.IsSampleMode = isSampleMode; return(settings); }
static public IEmailSmtpSettings GetSmtpSettingsFromAppSettings() { var settings = new EmailSmtpSettings(); settings.SmtpHost = AppSettings.SMTP_ServerHost; settings.SmtpPort = Int32.Parse(AppSettings.SMTP_ServerPort); settings.SmtpUsername = AppSettings.SMTP_EmailUsername; settings.SmtpPassword = AppSettings.SMTP_EmailPassword; settings.SmtpFromEmail = AppSettings.SMTP_EmailUsername; settings.SmtpFromDisplayName = AppSettings.SMTP_DisplayFromEmail; settings.IsDebug = AppSettings.IsDebug; return(settings); }
private ActionResult CreateMailMessage(Job job, EmailSmtpSettings mailSettings, SmtpAccount sender, out MailMessage mailMessage) { var mailInfo = _mailHelper.CreateMailInfo(job, mailSettings); mailMessage = null; try { mailMessage = mailMessage = new MailMessage(sender.Address, mailInfo.Recipients) { Subject = mailInfo.Subject, Body = mailInfo.Body, IsBodyHtml = mailInfo.IsHtml }; if (!string.IsNullOrWhiteSpace(mailInfo.RecipientsBcc)) //Prevent MailMessage from throwing and exception if BCC is not set { mailMessage.Bcc.Add(mailInfo.RecipientsBcc); } if (!string.IsNullOrWhiteSpace(mailInfo.RecipientsCc)) //Prevent MailMessage from throwing and exception if CC is not set { mailMessage.CC.Add(mailInfo.RecipientsCc); } } catch { return(new ActionResult(ErrorCode.Smtp_InvalidRecipients)); } foreach (var attachment in mailInfo.Attachments) { try { mailMessage.Attachments.Add(new Attachment(attachment)); } catch { Logger.Error("Invalid SMTP attachment: " + attachment); return(new ActionResult(ErrorCode.Smtp_InvalidAttachmentFiles)); } } return(new ActionResult()); }
private string GetRecipientsString(EmailSmtpSettings smtpSettings, TokenReplacer tokenReplacer) { var recipientsTo = tokenReplacer.ReplaceTokens(smtpSettings.Recipients); var recipientsCc = tokenReplacer.ReplaceTokens(smtpSettings.RecipientsCc); var recipientsBcc = tokenReplacer.ReplaceTokens(smtpSettings.RecipientsBcc); var sb = new StringBuilder(); sb.AppendLine($"{_translation.RecipientsToText} {recipientsTo}"); if (!string.IsNullOrWhiteSpace(recipientsCc)) { sb.AppendLine($"{_translation.RecipientsCcText} {recipientsCc}"); } if (!string.IsNullOrWhiteSpace(recipientsBcc)) { sb.AppendLine($"{_translation.RecipientsBccText} {recipientsBcc}"); } return(sb.ToString()); }
public string ComposeMailSignature(EmailSmtpSettings mailSettings) { return(ComposeMailSignature(mailSettings.AddSignature)); }
public void Setup() { Database.SetInitializer <AmazonContext>(null); XmlConfigurator.Configure(new FileInfo(AppSettings.log4net_Config)); _dbFactory = new DbFactory(); _time = new TimeService(_dbFactory); _settings = new SettingsService(_dbFactory); _styleHistoryService = new StyleHistoryService(_log, _time, _dbFactory); _styleManager = new StyleManager(_log, _time, _styleHistoryService); _actionService = new SystemActionService(_log, _time); _quantityManager = new QuantityManager(_log, _time); _priceManager = new PriceManager(_log, _time, _dbFactory, _actionService, _settings); _cacheService = new CacheService(_log, _time, _actionService, _quantityManager); _barcodeService = new BarcodeService(_log, _time, _dbFactory); _weightService = new WeightService(); IEmailSmtpSettings smtpSettings = new EmailSmtpSettings(); using (var db = new UnitOfWork()) { _company = db.Companies.GetFirstWithSettingsAsDto(); if (AppSettings.IsDebug) { smtpSettings = SettingsBuilder.GetSmtpSettingsFromAppSettings(); } else { smtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(_company); } _addressService = AddressService.Default; _emailService = new EmailService(_log, smtpSettings, _addressService); //todo check itemHist _autoCreateNonameListingService = new AutoCreateNonameListingService(_log, _time, _dbFactory, _cacheService, _barcodeService, _emailService, null, AppSettings.IsDebug); var marketplaces = new MarketplaceKeeper(_dbFactory, true); marketplaces.Init(); var shipmentPrividers = db.ShipmentProviders.GetByCompanyId(_company.Id); var apiFactory = new MarketFactory(marketplaces.GetAll(), _time, _log, _dbFactory, AppSettings.JavaPath); var weightService = new WeightService(); var serviceFactory = new ServiceFactory(); var rateProviders = serviceFactory.GetShipmentProviders(_log, _time, _dbFactory, weightService, shipmentPrividers, null, null, null, null); _magentoApi = (Magento20MarketApi)apiFactory.GetApi(_company.Id, MarketType.Magento, MarketplaceKeeper.ShopifyDWS); _shopifyDWSApi = (ShopifyApi)apiFactory.GetApi(_company.Id, MarketType.Shopify, MarketplaceKeeper.ShopifyDWS); _eBayApi = (eBayApi)apiFactory.GetApi(_company.Id, MarketType.eBay, ""); _amazonApi = (AmazonApi)apiFactory.GetApi(_company.Id, MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId); _walmartApi = (WalmartApi)apiFactory.GetApi(_company.Id, MarketType.Walmart, ""); } }