public ActionResult Bulk_Email(BulkEmail model) { if (ModelState.IsValid) { try { var message = new SendGridMessage(); String subject = model.Subject; String contents = model.Contents; EmailSender es = new EmailSender(); var users = db.AspNetUsers.ToList(); for (var i = 0; i < users.Count; i++) { es.Send(users[i].Email, subject, contents); } ViewBag.Result = "Email has been sent!"; ModelState.Clear(); return(View(new BulkEmail())); } catch { return(View()); } } return(View()); }
/// <summary> /// Prepares message before sending. /// </summary> /// <param name="userConnection">Instance of user connection.</param> public void PrepareMessage(UserConnection userConnection) { BulkEmail = new BulkEmail(userConnection); BulkEmail.FetchFromDB(MessageId); SendDate = DateTime.UtcNow; MailingStartTS = ConvertDateTimeToTimestamp(SendDate); }
/// <summary> /// Initalizes email data. /// </summary> /// <param name="bulkEmail">Email instance.</param> /// <param name="messageInfo">Data nexessary for email sending.</param> private EmailMessage InitEmailMessage(IMessageInfo messageInfo) { var instantMessageInfo = messageInfo as InstantMessageInfo; BulkEmail bulkEmail = instantMessageInfo.BulkEmail; var messageImages = new List <image>(); var message = new EmailMessage { subject = bulkEmail.TemplateSubject, from_email = bulkEmail.SenderEmail, from_name = bulkEmail.SenderName, html = bulkEmail.TemplateBody, track_clicks = true, track_opens = true, images = messageImages, inline_css = true, important = true }; var macrosHelper = new MarketingMacrosHelper(_userConnection); string templateCode = GetTemplate(bulkEmail, messageInfo, messageImages, macrosHelper); var bulkEmailId = bulkEmail.GetTypedColumnValue <Guid>("Id"); PrepareRecipient(messageInfo, macrosHelper, message, bulkEmailId); message.html = templateCode; if (_isMetadataInitialized) { message.AddMetadata(BulkEmailMetadataValue, messageInfo.MessageId.ToString("N")); } if (macrosHelper.GlobalMergeVars.Any()) { message.InitGlobalVariable(); message.global_merge_vars.AddRange(macrosHelper.GlobalMergeVars); } return(message); }
/// <summary> /// Creates empty instance of the <see cref="CESMailingTemplate"/>. /// </summary> /// <param name="userConnection">Instance of the user connection.</param> /// <param name="bulkEmail">Instance of the bulk email.</param> /// <param name="macroParser">Instance of the macros helper.</param> public CESMailingTemplate(UserConnection userConnection, BulkEmail bulkEmail, BulkEmailMacroParser macroParser) { _userConnection = userConnection; _bulkEmail = bulkEmail; _macroParser = macroParser; }
private BulkEmail GetBulkEmailFromDB(Guid bulkEmailId) { var bulkEmail = new BulkEmail(_userConnection); var fetchBulkEmailResult = bulkEmail.FetchFromDB("Id", bulkEmailId, new[] { "Id", "StartDate", "TemplateSubject", "SenderName", "SenderEmail", "UseUtm", "Domains", "UtmSource", "UtmMedium", "UtmCampaign", "UtmTerm", "UtmContent" }); if (fetchBulkEmailResult) { return(bulkEmail); } MailingUtilities.Log.WarnFormat( "[CESMaillingProvider.GetBulkEmailFromDB]: FetchFromDB BulkEmail: {0} fails.", bulkEmailId); throw new Exception( $"[CESMaillingProvider.GetBulkEmailFromDB]: FetchFromDB BulkEmail: {bulkEmailId} fails."); }
Microsoft.Office.Tools.Outlook.IFormRegion Microsoft.Office.Tools.Outlook.IFormRegionFactory.CreateFormRegion(Microsoft.Office.Interop.Outlook.FormRegion formRegion) { BulkEmail form = new BulkEmail(formRegion); form.Factory = this; return(form); }
protected void SaveTemplate(IMailingTemplate template, BulkEmail bulkEmail) { if (!Validator.ValidateTemplateSize(template, out var templateSize)) { throw new Exception( $"Template {template.Name} have size {templateSize} more than {MailingMaxTemplateSize}."); } var images = template.InlineImages.ToCESImage(); var checksum = string.Empty; string replicaId = null; string senderEmail; string senderName; if (template is IMailingTemplateWithHeaders templateReplica) { checksum = templateReplica.Checksum; replicaId = templateReplica.ReplicaId.ToString(); senderEmail = templateReplica.SenderEmail; senderName = templateReplica.SenderName; } else { senderEmail = bulkEmail.SenderEmail; senderName = bulkEmail.SenderName; } Utilities.RetryOnFailure(() => ServiceApi.AddTemplate(template.Name, senderEmail, senderName, template.TemplateSubject, template.Content, string.Empty, bulkEmail.Id, images, checksum, replicaId)); }
private SendMessageData CreateSendMessageData(BulkEmail bulkEmail) { var startDateUtc = TimeZoneInfo.ConvertTimeToUtc(bulkEmail.StartDate, Context.UserConnection.CurrentUser.TimeZone); var messageData = new SendMessageData { UserConnection = Context.UserConnection, BulkEmailStartDate = startDateUtc }; return(messageData); }
protected IEnumerable <IMailingTemplate> CreateTemplates(BulkEmail bulkEmail, BulkEmailMacroParser macroParser, IEnumerable <int> replicaMasksToProcess = null) { var templateReadOptions = new DCRepositoryReadOptions <DCTemplateModel, DCReplicaModel> { TemplateReadOptions = DCTemplateReadOption.None }; var template = TemplateRepository.ReadByRecordId(bulkEmail.Id, templateReadOptions); var replicas = GetReplicasByMasks(template, replicaMasksToProcess); return(CreateTemplates(bulkEmail, macroParser, replicas)); }
private SendMessageData CreateSendMessageData(BulkEmail bulkEmail) { var startDateUtc = TimeZoneInfo.ConvertTimeToUtc(bulkEmail.StartDate, _userConnection.CurrentUser.TimeZone); var messageData = new SendMessageData { UserConnection = _userConnection, BulkEmail = bulkEmail, BulkEmailStartDate = startDateUtc, SessionId = Guid.NewGuid() }; return(messageData); }
private EmailResult GetBulkEmailResult(EmailRequest request) { BulkEmail bulkEmail = request as BulkEmail; BulkEmailResult bulkEmailResult = new BulkEmailResult(); foreach (var email in bulkEmail.Emails) { var singleEmailResult = GetSingleEmailResult(email); bulkEmailResult.Results.Add(singleEmailResult); } return(bulkEmailResult); }
private BulkEmailResult RunRuleOnBulkEmail(BulkEmail bulkEmail) { BulkEmailResult bulkEmailResult = new BulkEmailResult(); foreach (var singleEmail in bulkEmail.Emails) { var singleEmailResult = checkTheToEmailIsValid(singleEmail); bulkEmailResult.Results.Add(singleEmailResult); } return(bulkEmailResult); }
private BulkEmailResult RunRuleOnBulkEmail(BulkEmail bulkEmail) { BulkEmailResult bulkEmailResult = new BulkEmailResult(); foreach (var singleEmail in bulkEmail.Emails) { var singleEmailResult = checkIfAlreadyUnsubcribed(singleEmail); bulkEmailResult.Results.Add(singleEmailResult); } return(bulkEmailResult); }
public static UtmData ConvertToUtmData(this BulkEmail bulkEmail, string templateCode) { return(new UtmData { UseUtm = bulkEmail.UseUtm, Domains = bulkEmail.Domains, UtmSource = bulkEmail.UtmSource, UtmMedium = bulkEmail.UtmMedium, UtmCampaign = bulkEmail.UtmCampaign, UtmTerm = bulkEmail.UtmTerm, UtmContent = bulkEmail.UtmContent, TemplateCode = templateCode }); }
private void PrepareRecipientsMacros(BulkEmail bulkEmail, List <IMailingTemplate> templateReplicas) { var macroComposer = GetMacroComposer(bulkEmail.OwnerId, bulkEmail.Id); foreach (var replica in templateReplicas) { var mailingTemplateReplica = replica as IMailingTemplateReplica; if (mailingTemplateReplica != null) { macroComposer.TrackedAliases = (mailingTemplateReplica as CESMailingTemplate)?.TrackedAliases; macroComposer.PrepareMacros(mailingTemplateReplica.ReplicaId, replica.MacrosCollection); } } }
public EmailResult RunAllRules(ref EmailRequest request) { var ruleEvalResult = GetDefaultEmailResult(request); foreach (var rule in _rules) { //run each rules precondition check ruleEvalResult = rule.RunRuleChecks(ref request); switch (ruleEvalResult) { case SingleEmailResult singleEmailResult: if (singleEmailResult.ErrorCode != OpResultCode.SUCCCESS) { return(singleEmailResult); } break; case BulkEmailResult bulkEmailResult: //so for bulk email result we have to do some juggling //if an email in the bulk emails fails a rule check //we remove it from the remaining bulk emails on //the next rule run //basically only emails that pass a rule check can be checked by //subsequent rule checks var failedResults = bulkEmailResult.Results.FindAll(i => i.ErrorCode != OpResultCode.SUCCCESS); var bulkEmailRequest = request as BulkEmail; request = new BulkEmail { Emails = GetRemainingEmailsThatPassedRuleCheck(failedResults, bulkEmailRequest) }; BulkEmails.AddRange(failedResults.ToList()); break; } } switch (ruleEvalResult) { case BulkEmailResult bulkEmailResult: BulkEmails.AddRange(bulkEmailResult.Results); return(BulkEmails); } return(ruleEvalResult); }
private List <string> GetBulkEmailCategoryTags(BulkEmail bulkEmail) { var tags = new List <string>(); var categoryId = bulkEmail.CategoryId; if (categoryId == MailingConsts.MassmailingBulkEmailCategoryId) { tags.Add(MassMailingTag); } else if (categoryId == MailingConsts.TriggeredEmailBulkEmailCategoryId) { tags.Add(TriggeredEmailTag); } return(tags); }
/// <summary> /// Initializes a new instance of the <see cref="BulkEmailAudienceDataSource"/> class. /// </summary> /// <param name="userConnection">Current user connection.</param> /// <param name="bulkEmailId">The bulk email identifier.</param> /// <param name="batchSize">Size of the batch of the recipients to select.</param> public BulkEmailAudienceDataSource(UserConnection userConnection, Guid bulkEmailId, int batchSize) { _userConnection = userConnection; var argsRecipientMacroRepository = GetArgumentsRecipientMacroRepository(userConnection); _bulkEmailRecipientMacroRepository = ClassFactory.Get <BulkEmailRecipientMacroRepository>(argsRecipientMacroRepository); _batchSize = batchSize; _bulkEmail = new BulkEmail(_userConnection); _bulkEmail.FetchFromDB("Id", bulkEmailId, new[] { "Id", "Category", "SendStartDate", "StartDate", "IsSystemEmail" }); _bulkEmailExpirationPeriod = (int)Core.Configuration.SysSettings.GetValue(userConnection, "BulkEmailExpirationPeriod"); _duplicatingRecipients = new Lazy <Dictionary <Guid, int> >(GetAudienceDuplicateResponses); InitCommunicationRestrictions(userConnection, bulkEmailId); }
private string GetTemplate(BulkEmail bulkEmail, IMessageInfo messageInfo, List <image> messageImages, MarketingMacrosHelper macrosHelper) { string templateBodyWithMacros = macrosHelper.SetTemplateBody(bulkEmail.TemplateBody, bulkEmail.OwnerId, bulkEmail.Id, messageInfo.ApplicationUrl); string templateCode = InlineimagesProcessing(templateBodyWithMacros, messageImages, messageInfo.ApplicationUrl); if (string.IsNullOrEmpty(templateCode)) { return(string.Empty); } templateCode = UtmHelper.GetTemplateCodeWithUtmLabel(bulkEmail.ConvertToUtmData(templateCode), messageInfo.MessageRId, macrosHelper.UnsubscribeMacrosAliases); int templateSize = MandrillUtilities.GetTemplateSize(templateCode, messageImages); return(templateSize > MandrillMaxTemplateSize ? string.Empty : templateCode); }
public async Task <IActionResult> ProcessBatchEmailRequest([FromBody] List <SingleEmail> emailRequests) { var cmd = new BulkEmail { Emails = emailRequests }; var result = await _apiListenerActor.Ask(cmd); switch (result) { case BulkEmailResult response: return(Ok(response.Results)); default: return(StatusCode(StatusCodes.Status500InternalServerError, result)); } }
private NotifyByEmailCmd GetSendEmailCmd(ApplyBussinessRulesCmd request, SingleEmailResult singleEmailResult) { switch (request.EmailRequest) { case SingleEmail singleEmail: return(new NotifyByEmailCmd { EmailRequest = singleEmail }); default: BulkEmail bulkEmail = request.EmailRequest as BulkEmail; return(new NotifyByEmailCmd { EmailRequest = bulkEmail.Emails.Find(i => i.UniqueEmailID == singleEmailResult.UniqueEmailID) }); } }
public ActionResult BulkEmail(FormCollection formCollection) { if (ModelState.IsValid) { try { ApplicationDbContext db = new ApplicationDbContext(); //get All Emails var users = db.Users.ToList(); var Emaillist = new List <EmailAddress>(); foreach (var user in users) { Emaillist.Add(new EmailAddress(user.Email, user.UserName)); } var subject = "Notification"; var contents = "This is the notification from Easy parking"; var attachment = Request.Files["attachment"]; if (attachment.ContentLength > 0) { String path = Path.Combine(Server.MapPath("~/Content/Attachment/"), attachment.FileName); attachment.SaveAs(path); BulkEmail bk = new BulkEmail(); bk.SendBA(Emaillist, subject, contents, path, attachment.FileName); } else { BulkEmail bk = new BulkEmail(); bk.SendB(Emaillist, subject, contents); } ViewBag.Result = "Email has been send."; ModelState.Clear(); return(View(new SendEmailViewModel())); } catch { return(View()); } } return(View()); }
private object GetLogFailedEmailCmd(ApplyBussinessRulesCmd request, SingleEmailResult singleEmailResult) { switch (request.EmailRequest) { case SingleEmail singleEmail: return(new PersistentStorageActor.LogFailedEmailCmd { EmailRequest = singleEmail, FailureReason = singleEmailResult.Message }); default: BulkEmail bulkEmail = request.EmailRequest as BulkEmail; return(new PersistentStorageActor.LogFailedEmailCmd { EmailRequest = bulkEmail.Emails.Find(i => i.UniqueEmailID == singleEmailResult.UniqueEmailID), FailureReason = singleEmailResult.Message }); } }
public ActionResult Contact(BulkEmail model, HttpPostedFileBase fileUploader) { if (ModelState.IsValid) { //var currentUser = User.Identity.GetUserId(); //String email = db.AspNetUsers.Where(m => m.Id == currentUser).ToList().Single().Email.ToString(); MailMessage message = new MailMessage(); SmtpClient smtp = new SmtpClient(); message.Subject = model.Subject; message.Body = model.Body; var from = model.From; message.To.Add(new MailAddress("*****@*****.**")); if (model.Upload != null) { string fileName = Path.GetFileName(model.Upload.FileName); message.Attachments.Add(new System.Net.Mail.Attachment(model.Upload.InputStream, fileName)); } message.IsBodyHtml = false; smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential networkCredential = new NetworkCredential("*****@*****.**", "s@n@_2210_"); smtp.UseDefaultCredentials = false; smtp.Credentials = networkCredential; message.From = new MailAddress(from); smtp.Port = 587; smtp.Send(message); ViewBag.Result = "Thank You! We will get back to you shortly."; ModelState.Clear(); return(View(new BulkEmail())); } else { return(View()); } }
/// <summary> /// Gets the broken bulk emails list. /// </summary> /// <param name="userConnection">The user connection.</param> /// <returns>List of <see cref="BulkEmail"/>.</returns> public virtual List <BulkEmail> GetBrokenBulkEmails(UserConnection userConnection) { var preparingToSendTimeOut = (int)SysSettingsCore.GetValue(userConnection, "PreparingToSendTimeoutPeriod"); var sendingInProgressTimeOut = (int)SysSettingsCore.GetValue(userConnection, "SendingInProgressTimeoutPeriod"); Select bulkEmailSelect = CreateBulkEmailsSelect(userConnection); DateTime currentDate = DateTime.UtcNow; var resultList = new List <BulkEmail>(); using (DBExecutor dbExecutor = userConnection.EnsureDBConnection()) { using (IDataReader dr = bulkEmailSelect.ExecuteReader(dbExecutor)) { while (dr.Read()) { var sendStartDate = (DateTime)dr["SendStartDate"]; Guid statusId = userConnection.DBTypeConverter.DBValueToGuid(dr["StatusId"]); Guid launchOptionId = userConnection.DBTypeConverter.DBValueToGuid(dr["LaunchOptionId"]); int emailTimeout = statusId == MarketingConsts.BulkEmailStatusStartsId ? preparingToSendTimeOut : sendingInProgressTimeOut; if (currentDate <= sendStartDate.AddMinutes(emailTimeout)) { continue; } var bulkEmail = new BulkEmail(userConnection) { Id = userConnection.DBTypeConverter.DBValueToGuid(dr["Id"]), CategoryId = userConnection.DBTypeConverter.DBValueToGuid(dr["CategoryId"]), SendStartDate = sendStartDate, StatusId = statusId, LaunchOptionId = launchOptionId }; resultList.Add(bulkEmail); } } } return(resultList); }
private int GetMailingStartTs(BulkEmail bulkEmail) { var isTriggeredCategory = bulkEmail.CategoryId == MailingConsts.TriggeredEmailBulkEmailCategoryId; return(isTriggeredCategory ? Utilities.ConvertDateTimeToTimestamp(bulkEmail.StartDate) : 0); }
/// <summary> /// Creates instance of the <see cref="IMailingTemplate"/> for given replicas of dynamic content. /// </summary> /// <param name="userConnection">Instance of the user connection.</param> /// <param name="bulkEmail">Instance of the bulk email.</param> /// <param name="replicas">Replicas collection.</param> /// <param name="macroParser">Instance of the <see cref="BulkEmailMacroParser"/>.</param> /// <returns>Returns instance of the <see cref="IMailingTemplate"/>.</returns> public virtual IEnumerable <IMailingTemplate> CreateInstances(UserConnection userConnection, BulkEmail bulkEmail, IEnumerable <DCReplicaModel> replicas, BulkEmailMacroParser macroParser = null) { var templateReplicas = new List <IMailingTemplate>(); foreach (var replica in replicas) { var templateFromReplica = new CESMailingTemplate(userConnection, bulkEmail, macroParser); templateFromReplica.Content = replica.Content; templateFromReplica.ReplicaId = replica.Id; templateFromReplica.Init(); templateReplicas.Add(templateFromReplica); } return(templateReplicas); }
/// <summary> /// Creates instance of the <see cref="IMailingTemplate"/>. /// </summary> /// <param name="userConnection">Instance of the user connection.</param> /// <param name="bulkEmail">Instance of the bulk email.</param> /// <param name="macroParser">Instance of the macros parser.</param> /// <returns>Returns instance of the <see cref="IMailingTemplate"/>.</returns> public virtual IMailingTemplate CreateInstance(UserConnection userConnection, BulkEmail bulkEmail, BulkEmailMacroParser macroParser) { return(new CESMailingTemplate(userConnection, bulkEmail, macroParser)); }
/// <summary> /// Creates instance of the <see cref="IMailingTemplate"/> for every replica of dynamic content. /// </summary> /// <param name="userConnection">Instance of the user connection.</param> /// <param name="bulkEmail">Instance of the bulk email.</param> /// <param name="macroParser">Instance of the <see cref="BulkEmailMacroParser"/>.</param> /// <returns>Returns instance of the <see cref="IMailingTemplate"/>.</returns> public IEnumerable <IMailingTemplate> CreateDCTemplates(UserConnection userConnection, BulkEmail bulkEmail, BulkEmailMacroParser macroParser) { var templateRepository = CreateDcTemplateRepository(userConnection); var templateReadOptions = new DCRepositoryReadOptions <DCTemplateModel, DCReplicaModel> { TemplateReadOptions = DCTemplateReadOption.None }; var template = templateRepository.ReadByRecordId(bulkEmail.Id, templateReadOptions); IEnumerable <DCReplicaModel> replicas = null; if (template != null) { replicas = template.Replicas; } return(CreateInstances(userConnection, bulkEmail, replicas, macroParser)); }
private SendTestMessageResult ExecuteDCTestMessageSending(SendTestMessageData data, BulkEmail bulkEmail, SendMessageData messageData, IEnumerable <DCReplicaModel> replicas) { var sentReplicaMasks = new List <int>(); var failedReplicaMasks = new List <int>(); var templates = TemplateFactory.CreateInstances(_userConnection, bulkEmail, replicas, BulkEmailMacroParser); var templatesWithMasks = templates.Select(t => new { Template = t, ReplicaMask = replicas.First(replica => replica.Id == ((IMailingTemplateReplica)t).ReplicaId).Mask }); var macroComposer = GetMacroComposer(data.ContactId, bulkEmail.Id); foreach (var template in templatesWithMasks) { var sentSuccessfully = SendTestMessageTemplate(bulkEmail.Id, data.ContactId, data.EmailRecipients, template.Template, messageData, macroComposer); if (sentSuccessfully) { sentReplicaMasks.Add(template.ReplicaMask); } else { failedReplicaMasks.Add(template.ReplicaMask); } } if (data.ReplicaMasks == null) { return(new SendTestMessageResult { Success = sentReplicaMasks.Count > 0, SentReplicaMasks = sentReplicaMasks.ToArray(), FailedReplicaMasks = failedReplicaMasks.ToArray() }); } foreach (var mask in data.ReplicaMasks) { if (!sentReplicaMasks.Contains(mask) && !failedReplicaMasks.Contains(mask)) { failedReplicaMasks.Add(mask); } } return(new SendTestMessageResult { Success = sentReplicaMasks.Count > 0, SentReplicaMasks = sentReplicaMasks.ToArray(), FailedReplicaMasks = failedReplicaMasks.ToArray() }); }