public SendBatchEmailsOperation( List <int> fileID, List <int> contactID, String subject, String bodyTempate, bool storeInHistory) { Id = TenantProvider.CurrentTenantID; Percentage = 0; _fileID = fileID; _contactID = contactID; _subject = subject; _bodyTempate = bodyTempate; _log = LogManager.GetLogger("ASC.CRM.MailSender"); _tenantID = TenantProvider.CurrentTenantID; _smtpSetting = Global.TenantSettings.SMTPServerSetting; _currUser = SecurityContext.CurrentAccount.ID; _storeInHistory = storeInHistory; Status = new { RecipientCount = _contactID.Count, EstimatedTime = 0, DeliveryCount = 0 }; }
public SendBatchEmailsOperation( TenantUtil tenantUtil, IOptionsMonitor <ILog> logger, Global global, SecurityContext securityContext, TenantManager tenantManager, UserManager userManager, AuthManager authManager, SettingsManager settingsManager, DaoFactory daoFactory, CoreConfiguration coreConfiguration, FilesIntegration filesIntegration ) { _tenantUtil = tenantUtil; _securityContext = securityContext; Percentage = 0; _log = logger.Get("ASC.CRM.MailSender"); _tenantID = tenantManager.GetCurrentTenant().TenantId; var _crmSettings = settingsManager.Load <CrmSettings>(); _smtpSetting = new SMTPServerSetting(coreConfiguration.SmtpSettings); _currUser = _securityContext.CurrentAccount.ID; _authManager = authManager; _userManager = userManager; _daoFactory = daoFactory; _tenantManager = tenantManager; _filesIntegration = filesIntegration; }
public void StartSendTestMail(string recipientEmail, string mailSubj, string mailBody) { var log = _logManager.Get("ASC.CRM.MailSender"); if (!recipientEmail.TestEmailRegex()) { throw new Exception(string.Format(CRMCommonResource.MailSender_InvalidEmail, recipientEmail)); } _tenantManager.SetCurrentTenant(_tenantID); var smtpSetting = new SMTPServerSetting(_coreConfiguration.SmtpSettings); ThreadPool.QueueUserWorkItem(_ => { try { var toAddress = new MailboxAddress(recipientEmail); var fromAddress = new MailboxAddress(smtpSetting.SenderDisplayName, smtpSetting.SenderEmailAddress); var mimeMessage = new MimeMessage { Subject = mailSubj }; mimeMessage.From.Add(fromAddress); mimeMessage.To.Add(toAddress); var bodyBuilder = new BodyBuilder { TextBody = mailBody }; mimeMessage.Body = bodyBuilder.ToMessageBody(); mimeMessage.Headers.Add("Auto-Submitted", "auto-generated"); using (var smtpClient = GetSmtpClient(smtpSetting)) { smtpClient.Send(FormatOptions.Default, mimeMessage, CancellationToken.None); } } catch (Exception ex) { log.Error(ex); } }); }
private SmtpClient GetSmtpClient(SMTPServerSetting smtpSetting) { var client = new SmtpClient { ServerCertificateValidationCallback = (sender, certificate, chain, errors) => MailService.DefaultServerCertificateValidationCallback(sender, certificate, chain, errors), Timeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds }; client.Connect(smtpSetting.Host, smtpSetting.Port, smtpSetting.EnableSSL ? SecureSocketOptions.Auto : SecureSocketOptions.None); if (smtpSetting.RequiredHostAuthentication) { client.Authenticate(smtpSetting.HostLogin, smtpSetting.HostPassword); } return(client); }
public SendBatchEmailsOperation( List<int> fileID, List<int> contactID, String subject, String bodyTempate, bool storeInHistory) { Id = TenantProvider.CurrentTenantID; Percentage = 0; _fileID = fileID; _contactID = contactID; _subject = subject; _bodyTempate = bodyTempate; _log = LogManager.GetLogger("ASC.CRM.MailSender"); _tenantID = TenantProvider.CurrentTenantID; _daoFactory = Global.DaoFactory; _smtpSetting = Global.TenantSettings.SMTPServerSetting; _currUser = ASC.Core.SecurityContext.CurrentAccount.ID; _storeInHistory = storeInHistory; Status = new { RecipientCount = _contactID.Count, EstimatedTime = 0, DeliveryCount = 0 }; }