public static IProgressItem Start(List <int> fileID, List <int> contactID, String subject, String bodyTemplate, bool storeInHistory) { lock (_syncObj) { var operation = _mailQueue.GetStatus(TenantProvider.CurrentTenantID); if (operation == null) { if (fileID == null) { fileID = new List <int>(); } if (contactID == null || contactID.Count == 0 || String.IsNullOrEmpty(subject) || String.IsNullOrEmpty(bodyTemplate)) { return(null); } if (contactID.Count > GetQuotas()) { contactID = contactID.Take(GetQuotas()).ToList(); } operation = new SendBatchEmailsOperation(fileID, contactID, subject, bodyTemplate, storeInHistory); _mailQueue.Add(operation); } if (!_mailQueue.IsStarted) { _mailQueue.Start(x => x.RunJob()); } return(operation); } }
public MailSender( IConfiguration configuration, TenantManager tenantManager, SettingsManager settingsManager, DistributedTaskQueueOptionsManager progressQueueOptionsManager, SendBatchEmailsOperation sendBatchEmailsOperation, CoreConfiguration coreConfiguration, IOptionsMonitor <ILog> logger ) { _sendBatchEmailsOperation = sendBatchEmailsOperation; _tenantID = tenantManager.GetCurrentTenant().TenantId; _mailQueue = progressQueueOptionsManager.Get <SendBatchEmailsOperation>(); _coreConfiguration = coreConfiguration; _logManager = logger; int parsed; if (int.TryParse(configuration["crm:mailsender:quotas"], out parsed)) { quotas = parsed; } _tenantManager = tenantManager; _settingsManager = settingsManager; // LogManager = logger.Get(); }
public static void StartSendTestMail(String recipientEmail, String mailSubj, String mailBody) { var log = LogManager.GetLogger("ASC.CRM.MailSender"); var smtpSetting = Global.TenantSettings.SMTPServerSetting; var smtpClient = new SmtpClient(smtpSetting.Host, smtpSetting.Port); if (smtpSetting.RequiredHostAuthentication) { smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential(smtpSetting.HostLogin, smtpSetting.HostPassword); } smtpClient.EnableSsl = smtpSetting.EnableSSL; ASC.Core.CoreContext.TenantManager.SetCurrentTenant(TenantProvider.CurrentTenantID); var from = new MailAddress(smtpSetting.SenderEmailAddress, smtpSetting.SenderDisplayName, Encoding.UTF8); if (!SendBatchEmailsOperation.isValidMail(recipientEmail)) { throw new Exception(String.Format(CRMCommonResource.MailSender_InvalidEmail, recipientEmail)); } var to = new MailAddress(recipientEmail); var message = new MailMessage(from, to); try { message.Subject = mailSubj; message.Body = mailBody; message.SubjectEncoding = Encoding.UTF8; message.BodyEncoding = Encoding.UTF8; message.IsBodyHtml = false; smtpClient.Timeout = 10000;//in ms log.Debug(SendBatchEmailsOperation.GetLoggerRow(message)); ThreadPool.QueueUserWorkItem(_ => { try { smtpClient.Send(message); message.Dispose(); } catch (Exception ex) { log.Error(ex.Message); } }); } catch (Exception ex) { message.Dispose(); log.Error(ex.Message); } }
public object Clone() { var cloneObj = new SendBatchEmailsOperation(); cloneObj.Error = Error; cloneObj.Id = Id; cloneObj.IsCompleted = IsCompleted; cloneObj.Percentage = Percentage; cloneObj.Status = Status; return(cloneObj); }
public static void Insert(SendBatchEmailsOperation data) { Cache.Insert(GetStateCacheKey(), data, TimeSpan.FromMinutes(1)); }
public static IProgressItem Start(List<int> fileID, List<int> contactID, String subject, String bodyTemplate, bool storeInHistory) { lock (_syncObj) { var operation = _mailQueue.GetStatus(TenantProvider.CurrentTenantID); if (operation == null) { if (fileID == null) fileID = new List<int>(); if (contactID == null || contactID.Count == 0) return null; if (String.IsNullOrEmpty(subject) || String.IsNullOrEmpty(bodyTemplate)) return null; if (contactID.Count > GetQuotas()) contactID = contactID.Take(GetQuotas()).ToList(); operation = new SendBatchEmailsOperation( fileID, contactID, subject, bodyTemplate, storeInHistory ); _mailQueue.Add(operation); } if (!_mailQueue.IsStarted) _mailQueue.Start(x => x.RunJob()); return operation; } }
public object Clone() { var cloneObj = new SendBatchEmailsOperation(); cloneObj.Error = Error; cloneObj.Id = Id; cloneObj.IsCompleted = IsCompleted; cloneObj.Percentage = Percentage; cloneObj.Status = Status; return cloneObj; }