Exemple #1
0
 /// <summary>
 /// Queues a templage-based email message to be sent in the background.
 /// Use the token options argument to indicate the prefix and/or suffix used to denote token placeholders within the referenced template.
 /// </summary>
 public static void AddToQueue(string templateName, DataRow tokens, InfTokenOptions tokenOptions, IDictionary <string, byte[]> attachments, long lastUpdatedUserId)
 {
     AddToQueue(templateName, tokens.ToDictionary(), tokenOptions, attachments, lastUpdatedUserId);
 }
Exemple #2
0
 /// <summary>
 /// Queues a templage-based email message to be sent in the background.
 /// Use the token options argument to indicate the prefix and/or suffix used to denote token placeholders within the referenced template.
 /// <param name="lastUpdatedUserId"></param>
 public static void AddToQueue(string templateName, object tokens, InfTokenOptions tokenOptions, long lastUpdatedUserId)
 {
     AddToQueue(templateName, tokens.ToDictionary(), tokenOptions, lastUpdatedUserId);
 }
Exemple #3
0
        public static void AddToQueue(string templateName, IDictionary <string, object> tokens, InfTokenOptions tokenOptions, IDictionary <string, byte[]> attachments, long lastUpdatedUserId)
        {
            var emailTemplateRow = InfEmailDataAccess.GetEmailTemplateByName(templateName);

            if (emailTemplateRow == null)
            {
                throw new ArgumentException("Email template not found.", "templateName");
            }

            var fromAddress = emailTemplateRow["FromAddress"].ToString().ReplaceTokens(tokens, tokenOptions);
            var toAddress   = emailTemplateRow["ToAddress"].ToString().ReplaceTokens(tokens, tokenOptions);
            var ccAddress   = emailTemplateRow["CcAddress"].ToString().ReplaceTokens(tokens, tokenOptions);
            var bccAddress  = emailTemplateRow["BccAddress"].ToString().ReplaceTokens(tokens, tokenOptions);
            var subject     = emailTemplateRow["Subject"].ToString().ReplaceTokens(tokens, tokenOptions);
            var body        = emailTemplateRow["Body"].ToString().ReplaceTokens(tokens, tokenOptions);
            var priority    = emailTemplateRow["Priority"].ToString();
            var htmlInd     = emailTemplateRow["HtmlInd"].ToString().StartsWith("Y", StringComparison.OrdinalIgnoreCase);

            using (var email = new MailMessage(fromAddress, toAddress, subject, body))
            {
                email.IsBodyHtml = htmlInd;

                if (!string.IsNullOrWhiteSpace(ccAddress))
                {
                    email.CC.Add(ccAddress);
                }

                if (!string.IsNullOrWhiteSpace(bccAddress))
                {
                    email.Bcc.Add(bccAddress);
                }

                if (!string.IsNullOrWhiteSpace(priority))
                {
                    email.Priority = (MailPriority)Enum.Parse(typeof(MailPriority), priority, true);
                }

                if (attachments != null)
                {
                    foreach (var item in attachments)
                    {
                        var attachmentName  = item.Key;
                        var attachmentBytes = item.Value;

                        using (var memoryStream = new MemoryStream(attachmentBytes))
                        {
                            using (var attachment = new Attachment(memoryStream, attachmentName))
                            {
                                email.Attachments.Add(attachment);
                            }
                        }
                    }
                }

                AddToQueue(email, lastUpdatedUserId);
            }
        }
Exemple #4
0
 /// <summary>
 /// Queues a templage-based email message to be sent in the background.
 /// Use the token options argument to indicate the prefix and/or suffix used to denote token placeholders within the referenced template.
 /// <param name="lastUpdatedUserId"></param>
 public static void AddToQueue(string templateName, IDictionary <string, object> tokens, InfTokenOptions tokenOptions, long lastUpdatedUserId)
 {
     AddToQueue(templateName, tokens, tokenOptions, null, lastUpdatedUserId);
 }