protected string BuildEmailValues(Guid customerOrderID, IUnitOfWork unitOfWork) { CustomerOrder customerOrder = unitOfWork.GetRepository <CustomerOrder>().Get(customerOrderID); string str1 = string.Empty; if (customerOrder.ApproverUserProfileId != null && !String.IsNullOrEmpty(customerOrder.PlacedByUserProfile.Email)) { string userEmail = customerOrder.PlacedByUserProfile.Email; char[] chArray = new char[2] { ',', ';' }; foreach (string possibleEmail in userEmail.Split(chArray)) { if (RegularExpressionLibrary.IsValidEmail(possibleEmail) && !str1.Contains(possibleEmail)) { string str2 = str1; string str3 = str2.Length > 0 ? "," : string.Empty; string str4 = possibleEmail; str1 = str2 + str3 + str4; } } } return(str1); //trigger email for BUSA-625 end. }
/// <summary> /// Gets the library. /// </summary> private void GetRegularExpressionLibrary() { // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer serializer = new XmlSerializer(typeof(RegularExpressionLibrary)); // To read the file, create a FileStream. using (FileStream fileStream = new FileStream(Application.StartupPath + @"\RegExLibrary.xml", FileMode.Open)) { // Call the Deserialize method and cast to the object type. this.library = (RegularExpressionLibrary)serializer.Deserialize(fileStream); } }
/// <summary> /// Loads the regular expression library. /// </summary> private void LoadRegularExpressionLibrary() { if (File.Exists(Application.StartupPath + @"\RegExLibrary.xml") == false) { this.treeView1.Enabled = false; this.toolStripButtonLibrary.Enabled = false; this.labelLibrary.Text = "Task Library not Available"; return; } try { // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer serializer = new XmlSerializer(typeof(RegularExpressionLibrary)); // To read the file, create a FileStream. using (FileStream fileStream = new FileStream(Application.StartupPath + @"\RegExLibrary.xml", FileMode.Open)) { // Call the Deserialize method and cast to the object type. this.mylibrary = (RegularExpressionLibrary)serializer.Deserialize(fileStream); } foreach (Library lib in this.mylibrary.Library) { TreeNode libNode = new TreeNode(lib.libraryname); foreach (task t in lib.task) { TreeNode taskNode = new TreeNode(t.name); libNode.Nodes.Add(taskNode); } this.treeView1.Nodes.Add(libNode); } this.treeView1.Enabled = true; this.toolStripButtonLibrary.Enabled = true; this.labelLibrary.Text = "Task Library"; } catch (Exception ex) { MessageBox.Show("There was en error loading the Regular Expression Library: " + Environment.NewLine + ex.Message, "Library Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.treeView1.Enabled = false; } }
protected virtual MailMessage ConvertEmailMessageToMailMessage(EmailMessage emailMessage) { ICollection <EmailMessageAddress> messageAddresses1 = emailMessage.EmailMessageAddresses; Func <EmailMessageAddress, bool> func1 = (Func <EmailMessageAddress, bool>)(o => o.Type != EmailMessageAddressType.From.ToString()); Func <EmailMessageAddress, bool> predicate1; if (messageAddresses1.All <EmailMessageAddress>(func1)) { throw new ArgumentException("There were not any EmailMessageAddresses with a From type."); } ICollection <EmailMessageAddress> messageAddresses2 = emailMessage.EmailMessageAddresses; Func <EmailMessageAddress, bool> func2 = (Func <EmailMessageAddress, bool>)(o => o.Type == EmailMessageAddressType.From.ToString()); Func <EmailMessageAddress, bool> predicate2; if (messageAddresses2.Count <EmailMessageAddress>(func2) > 1) { throw new ArgumentException("There were multiple EmailMessageAddresses with a From type."); } ICollection <EmailMessageAddress> messageAddresses3 = emailMessage.EmailMessageAddresses; Func <EmailMessageAddress, bool> func3 = (Func <EmailMessageAddress, bool>)(o => o.Type != EmailMessageAddressType.To.ToString()); Func <EmailMessageAddress, bool> predicate3; if (messageAddresses3.All <EmailMessageAddress>(func3)) { throw new ArgumentException("There were not any EmailMessageAddresses with a To type."); } foreach (EmailMessageAddress emailMessageAddress in (IEnumerable <EmailMessageAddress>)emailMessage.EmailMessageAddresses) { if (!RegularExpressionLibrary.IsValidEmail(emailMessageAddress.EmailAddress)) { throw new ArgumentException("The value '{email}' on the EmailMessage with type {type} is not a valid email address".FormatWith((object)new { email = emailMessageAddress.EmailAddress, type = emailMessageAddress.Type }, (IFormatProvider)null)); } } MailMessage mailMessage = new MailMessage(); mailMessage.Body = emailMessage.Body; mailMessage.Subject = emailMessage.Subject; List <string> source = new List <string>() { "<html", "<body", "<div", "<a" }; mailMessage.IsBodyHtml = source.Any <string>((Func <string, bool>)(s => mailMessage.Body.Contains(s))); EmailMessageAddress emailMessageAddress1 = emailMessage.EmailMessageAddresses.FirstOrDefault <EmailMessageAddress>((Func <EmailMessageAddress, bool>)(o => o.Type == EmailMessageAddressType.From.ToString())); if (emailMessageAddress1 != null) { mailMessage.From = new MailAddress(emailMessageAddress1.EmailAddress); } foreach (EmailMessageAddress emailMessageAddress2 in emailMessage.EmailMessageAddresses.Where <EmailMessageAddress>((Func <EmailMessageAddress, bool>)(o => o.Type == EmailMessageAddressType.To.ToString()))) { mailMessage.To.Add(emailMessageAddress2.EmailAddress); } foreach (EmailMessageAddress emailMessageAddress2 in emailMessage.EmailMessageAddresses.Where <EmailMessageAddress>((Func <EmailMessageAddress, bool>)(o => o.Type == EmailMessageAddressType.BCC.ToString()))) { mailMessage.Bcc.Add(emailMessageAddress2.EmailAddress); } foreach (EmailMessageAddress emailMessageAddress2 in emailMessage.EmailMessageAddresses.Where <EmailMessageAddress>((Func <EmailMessageAddress, bool>)(o => o.Type == EmailMessageAddressType.CC.ToString()))) { mailMessage.CC.Add(emailMessageAddress2.EmailAddress); } foreach (EmailMessageAddress emailMessageAddress2 in emailMessage.EmailMessageAddresses.Where <EmailMessageAddress>((Func <EmailMessageAddress, bool>)(o => o.Type == EmailMessageAddressType.ReplyTo.ToString()))) { mailMessage.ReplyToList.Add(emailMessageAddress2.EmailAddress); } return(mailMessage); }
public void SendEmail(SendEmailParameter parameter, IUnitOfWork unitOfWork) { foreach (string toAddress in (IEnumerable <string>)parameter.ToAddresses) { if (!RegularExpressionLibrary.IsValidEmail(toAddress)) { throw new ArgumentException("The value '{email}' in the ToAddresses collection is not a valid email address".FormatWith((object)new { email = toAddress }, (IFormatProvider)null)); } } if (!RegularExpressionLibrary.IsValidEmail(parameter.FromAddress)) { throw new ArgumentException("The value '{email}' for the FromAddress is not a valid email address".FormatWith((object)new { email = parameter.FromAddress }, (IFormatProvider)null)); } foreach (string replyToAddress in (IEnumerable <string>)parameter.ReplyToAddresses) { if (!RegularExpressionLibrary.IsValidEmail(replyToAddress)) { throw new ArgumentException("The value '{email}' in the ReplyToAddresses collection is not a valid email address".FormatWith((object)new { email = replyToAddress }, (IFormatProvider)null)); } } foreach (string ccAddress in (IEnumerable <string>)parameter.CCAddresses) { if (!RegularExpressionLibrary.IsValidEmail(ccAddress)) { throw new ArgumentException("The value '{email}' in the CCAddresses collection is not a valid email address".FormatWith((object)new { email = ccAddress }, (IFormatProvider)null)); } } foreach (string bccAddress in (IEnumerable <string>)parameter.BccAddresses) { if (!RegularExpressionLibrary.IsValidEmail(bccAddress)) { throw new ArgumentException("The value '{email}' in the BccAddresses collection is not a valid email address".FormatWith((object)new { email = bccAddress }, (IFormatProvider)null)); } } IRepository <EmailMessage> repository = unitOfWork.GetRepository <EmailMessage>(); EmailMessage emailMessage = repository.Create(); emailMessage.Body = parameter.Body; emailMessage.Subject = parameter.Subject; repository.Insert(emailMessage); foreach (string toAddress in (IEnumerable <string>)parameter.ToAddresses) { emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress() { EmailAddress = toAddress, Type = EmailMessageAddressType.To.ToString() }); } emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress() { EmailAddress = parameter.FromAddress, Type = EmailMessageAddressType.From.ToString() }); foreach (string ccAddress in (IEnumerable <string>)parameter.CCAddresses) { emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress() { EmailAddress = ccAddress, Type = EmailMessageAddressType.CC.ToString() }); } foreach (string bccAddress in (IEnumerable <string>)parameter.BccAddresses) { emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress() { EmailAddress = bccAddress, Type = EmailMessageAddressType.BCC.ToString() }); } foreach (string replyToAddress in (IEnumerable <string>)parameter.ReplyToAddresses) { emailMessage.EmailMessageAddresses.Add(new EmailMessageAddress() { EmailAddress = replyToAddress, Type = EmailMessageAddressType.ReplyTo.ToString() }); } EmailMessageDeliveryAttempt emailMessageDeliveryAttempt = new EmailMessageDeliveryAttempt(); emailMessage.EmailMessageDeliveryAttempts.Add(emailMessageDeliveryAttempt); unitOfWork.Save(); string emailTestAddress = EmailsSettings.TestEmail; Task.Factory.StartNew((Action)(() => this.DoActualSend(emailMessage, emailMessageDeliveryAttempt, emailTestAddress))); }
//BUSA 590 : W04593 -Single Order confirmation email is triggered to customer and inside sales rep start. protected string BuildEmailValuesWithoutSalesRep(Guid customerOrderID, IUnitOfWork unitOfWork) { CustomerOrder customerOrder = unitOfWork.GetRepository <CustomerOrder>().Get(customerOrderID); string str1 = string.Empty; if (customerOrder.BTEmail.Length > 0) { string btEmail = customerOrder.BTEmail; char[] chArray = new char[2] { ',', ';' }; foreach (string possibleEmail in btEmail.Split(chArray)) { if (RegularExpressionLibrary.IsValidEmail(possibleEmail) && !str1.Contains(possibleEmail)) { string str2 = str1; string str3 = str2.Length > 0 ? "," : string.Empty; string str4 = possibleEmail; str1 = str2 + str3 + str4; } } } if (customerOrder.STEmail.Length > 0) { string stEmail = customerOrder.STEmail; char[] chArray = new char[2] { ',', ';' }; foreach (string possibleEmail in stEmail.Split(chArray)) { if (RegularExpressionLibrary.IsValidEmail(possibleEmail) && !str1.Contains(possibleEmail)) { string str2 = str1; string str3 = str2.Length > 0 ? "," : string.Empty; string str4 = possibleEmail; str1 = str2 + str3 + str4; } } } if (customerOrder.ApproverUserProfileId != null && !String.IsNullOrEmpty(customerOrder.PlacedByUserProfile.Email)) { string userEmail = customerOrder.PlacedByUserProfile.Email; char[] chArray = new char[2] { ',', ';' }; foreach (string possibleEmail in userEmail.Split(chArray)) { if (RegularExpressionLibrary.IsValidEmail(possibleEmail) && !str1.Contains(possibleEmail)) { string str2 = str1; string str3 = str2.Length > 0 ? "," : string.Empty; string str4 = possibleEmail; str1 = str2 + str3 + str4; } } } string byName = EmailsSettings.OrderNotificationEmail; if (byName.Length > 0 && RegularExpressionLibrary.IsValidEmail(byName) && !str1.Contains(byName)) { string str2 = str1; string str3 = str2.Length > 0 ? "," : string.Empty; string str4 = byName; str1 = str2 + str3 + str4; } return(str1); }
public override void SendEmailList(Guid emailListId, IList <string> toAddresses, ExpandoObject templateModel, string subject, IUnitOfWork unitOfWork, Guid?templateWebsiteId = null, IList <Attachment> attachments = null) { object SenderName; List <String> Sender = new List <String>(); foreach (string toAddress in toAddresses) { if (RegularExpressionLibrary.IsValidEmail(toAddress)) { continue; } throw new ArgumentException(string.Concat("To address: ", toAddress, " is not a valid email address.")); } EmailList emailList = this.GetEmailList(unitOfWork, emailListId, templateWebsiteId); if (emailList == null) { return; } //BUSA-1090 Wish list email notification (share) if (((IDictionary <String, Object>)templateModel).TryGetValue("SenderName", out SenderName)) { ((IDictionary <String, Object>)templateModel).TryGetValue("SenderName", out SenderName); Sender.Add(SenderName.ToString()); foreach (string CCAddress in Sender) { if (RegularExpressionLibrary.IsValidEmail(CCAddress)) { continue; } throw new ArgumentException(string.Concat("CC address: ", CCAddress, " is not a valid email address.")); } } //BUSA-1090 Wish list email notification (share) emailList.FromAddress = CustomSettings.DefaultWishListEmailAddress; // add toAddresses and ccAddresses for RMA notification object IsRmaEmail; List <string> ccAddresses = new List <string>(); if (((IDictionary <String, Object>)templateModel).TryGetValue("IsRmaEmail", out IsRmaEmail)) { if (!string.IsNullOrEmpty(CustomSettings.RMA_ToAddress)) { string[] addresses = CustomSettings.RMA_ToAddress.Split(';'); for (int i = 0; i < addresses.Length; i++) { toAddresses.Add(addresses[i].Trim()); } } if (!string.IsNullOrEmpty(CustomSettings.RMA_CC_Address)) { string[] addresses = CustomSettings.RMA_CC_Address.Split(';'); for (int i = 0; i < addresses.Length; i++) { ccAddresses.Add(addresses[i].Trim()); } } if (!string.IsNullOrEmpty(CustomSettings.RMA_BCC_Address)) { string[] addresses = CustomSettings.RMA_BCC_Address.Split(';'); for (int i = 0; i < addresses.Length; i++) { Sender.Add(addresses[i].Trim()); } } } SendEmailParameter sendEmailParameter = new SendEmailParameter() { ToAddresses = toAddresses, CCAddresses = ccAddresses, Attachments = attachments, BccAddresses = Sender, FromAddress = (emailList.FromAddress.IsBlank() ? this.EmailsSettings.DefaultEmail : emailList.FromAddress), Subject = (subject.IsBlank() ? this.EntityTranslationService.TranslateProperty <EmailList>(emailList, (EmailList o) => o.Subject) : subject) }; SendEmailParameter sendEmailParameter1 = sendEmailParameter; string htmlTemplate = this.GetHtmlTemplate(emailList, templateWebsiteId); this.ParseAndSendEmail(htmlTemplate, templateModel, sendEmailParameter1, unitOfWork); }