예제 #1
0
        /// <summary>
        /// Gets the MailAddress representation of the MailMergeAddress.
        /// </summary>
        /// <returns>Returns a MailAddress ready to be used for a MailAddress, or Null if no address part exists.</returns>
        /// <exception cref="NullReferenceException">Throws a NullReferenceException if TextVariableManager is null.</exception>
        /// <exception cref="FormatException">Throws a FormatException if the computed MailAddress is not valid.</exception>
        internal MailboxAddress GetMailAddress(MailMergeMessage mmm, object dataItem)
        {
            var address     = mmm.SearchAndReplaceVars(Address, dataItem);
            var displayName = mmm.SearchAndReplaceVars(DisplayName, dataItem);

            if (string.IsNullOrEmpty(displayName))
            {
                displayName = null;
            }

            // Exclude invalid address from further process
            if (!EmailValidator.Validate(address, false, true))
            {
                return(null);
            }

            return(displayName != null
                        ? new MailboxAddress(DisplayNameCharacterEncoding, displayName, address)
                        : new MailboxAddress(DisplayNameCharacterEncoding, address, address));
        }
예제 #2
0
        /// <summary>
        /// Gets the MailAddress representation of the MailMergeAddress.
        /// </summary>
        /// <returns>Returns a MailAddress ready to be used for a MailAddress, or Null if no address part exists.</returns>
        /// <exception cref="NullReferenceException">Throws a NullReferenceException if TextVariableManager is null.</exception>
        /// <exception cref="FormatException">Throws a FormatException if the computed MailAddress is not valid.</exception>
        internal MailboxAddress GetMailAddress(MailSmartFormatter formatter, object dataItem)
        {
            string address     = formatter.Format(Address, dataItem);
            string displayName = formatter.Format(DisplayName, dataItem);

            if (string.IsNullOrEmpty(displayName))
            {
                displayName = null;
            }

            // Exclude invalid address from further process
            if (!EmailValidator.Validate(address, false, true))
            {
                return(null);
            }

            return(displayName != null
                                    ? new MailboxAddress(DisplayNameCharacterEncoding, displayName, address)
                                    : new MailboxAddress(DisplayNameCharacterEncoding, address, address));
        }