/// <summary>
        /// Called when [pre dispatch].
        /// </summary>
        protected override void OnPreDispatch()
        {
            try
            {
                //Initializes mail message
                this.Mail = new MailMessage();

                //Add 'To' email address
                if (!ValidatorUtility.IsNullOrEmpty(this.ToAddresses))
                {
                    this.CreateAddressesFromString(Mail.To, this.ToAddresses);
                }
                else
                {
                    this.UpdateDisptachStatus(EmailDispatchStatus.NoEmailId);
                }

                //Set 'From' email address
                if (!ValidatorUtility.IsNullOrEmpty(this.FromAddress))
                {
                    if (ValidatorUtility.IsValidEmail(this.FromAddress))
                    {
                        Mail.From = new MailAddress(this.FromAddress);
                    }
                    else
                    {
                        this.UpdateDisptachStatus(EmailDispatchStatus.InvalidEmailId);
                    }
                }
                else
                {
                    this.UpdateDisptachStatus(EmailDispatchStatus.NoEmailId);
                }

                //Add 'Cc' email address
                if (!ValidatorUtility.IsNullOrEmpty(this.CcAddresses))
                {
                    this.CreateAddressesFromString(Mail.CC, this.CcAddresses);
                }

                //Add 'Bcc' email address
                if (!ValidatorUtility.IsNullOrEmpty(this.BccAddresses))
                {
                    this.CreateAddressesFromString(Mail.Bcc, this.BccAddresses);
                }

                //Set email Subject
                Mail.Subject = this.Subject;
                //Set email body
                Mail.Body       = this.Body;
                Mail.IsBodyHtml = true;
            }
            catch (Exception)
            {
                this.UpdateDisptachStatus(EmailDispatchStatus.Failure);
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Merges the message template text with placeholders
        /// </summary>
        /// <param name="messageTemplateText">The message template text.</param>
        /// <param name="placeholderValuesToMerge">The place holder values to merge.</param>
        /// <returns></returns>
        public static string MergeNotificationMessageText(string messageTemplateText,
                                                          Dictionary <string, string> placeholderValuesToMerge)
        {
            string mergedMessage = string.Empty;

            if (!ValidatorUtility.IsNull(messageTemplateText))
            {
                mergedMessage = messageTemplateText;
                if (placeholderValuesToMerge == null)
                {
                    placeholderValuesToMerge = new Dictionary <string, string>();
                }
                mergedMessage = mergedMessage.Inject(placeholderValuesToMerge, EmailConstants.templatePlaceholderStart,
                                                     EmailConstants.templatePlaceholderEnd);
            }
            return(mergedMessage);
        }
示例#3
0
 public static bool IsNullOrEmpty(string value)
 {
     // forward
     return(ValidatorUtility.IsNull(value));
 }
 /// <summary>
 /// This function finds if email addresses in a comma separated string are valid
 /// If all email addresses are valid only then the function returns true
 /// </summary>
 /// <param name="emailAddresses">comma separated string of email addresses</param>
 /// <returns></returns>
 private bool IsValidEmailAddresses(string emailAddresses)
 {
     string[] arrayAddresses = emailAddresses.Split(',');
     return(!(arrayAddresses.Any(emailAddress => !(ValidatorUtility.IsValidEmail(emailAddress.Trim())))));
 }
 /// <summary>
 /// Determines whether the specified attr is valid.
 /// </summary>
 /// <param name="attribute">The attr.</param>
 /// <returns>
 ///     <c>true</c> if the specified attr is valid; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsValid(DisplayTextKeyAttribute attribute)
 {
     return(attribute != null && !ValidatorUtility.IsNullOrEmpty(attribute.Key));
 }
 /// <summary>
 /// Determines whether the specified attr is valid.
 /// </summary>
 /// <param name="attribute">The attr.</param>
 /// <returns>
 ///     <c>true</c> if the specified attr is valid; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsValid(QualifiedTypeNameAttribute attribute)
 {
     return(attribute != null && !ValidatorUtility.IsNullOrEmpty(attribute.AssemblyFileName) && !ValidatorUtility.IsNullOrEmpty(attribute.QualifiedTypeName));
 }