Ejemplo n.º 1
0
        public string ToString(MailAddressType addrType)
        {
            TextVariableManager txtMgr = _mailMergeMessage.GetTextVariableManager().Clone();

            txtMgr.ShowEmptyAs = txtMgr.ShowNullAs = string.Empty;
            var addr = new StringBuilder();

            foreach (MailMergeAddress mmAddr in Get(addrType))
            {
                // copy all bad file names and bad variable names from "main" TextVariableManager
                txtMgr.BadFiles.AddRange(_mailMergeMessage.GetTextVariableManager().BadFiles);
                txtMgr.BadVariables.AddRange(_mailMergeMessage.GetTextVariableManager().BadVariables);

                mmAddr.TextVariableManager = txtMgr;
                addr.Append(mmAddr.ToString());

                // fill the "main" TextVariableManager with bad file/variable names
                _mailMergeMessage.GetTextVariableManager().BadFiles.Clear();
                _mailMergeMessage.GetTextVariableManager().BadFiles.AddRange(txtMgr.BadFiles);

                _mailMergeMessage.GetTextVariableManager().BadVariables.Clear();
                _mailMergeMessage.GetTextVariableManager().BadVariables.AddRange(txtMgr.BadVariables);

                addr.Append(", ");
            }

            if (addr.Length >= 2)
            {
                addr.Remove(addr.Length - 2, 2);
            }

            return(addr.ToString());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Represents the address of an electronic mail sender or recipient for use with a MailMergeMessage.
 /// </summary>
 /// <param name="addrType">MailAddressType of the e-mail address.</param>
 /// <param name="address">A string that contains an e-mail address.</param>
 /// <param name="displayName">A string that contains the display name associated with address. This parameter can be null.</param>
 public MailMergeAddress(MailAddressType addrType, string displayName, string address)
 {
     AddrType    = addrType;
     Address     = address;
     DisplayName = displayName;
     DisplayNameCharacterEncoding = null;
 }
Ejemplo n.º 3
0
        public void MailMergeAddressCollectionFind(MailAddressType addrType)
        {
            var addrColl = new MailMergeAddressCollection {
                _addr1a, _addr2a, _addr3
            };

            switch (addrType)
            {
            case MailAddressType.To:
                Assert.AreEqual(_addr1a, addrColl.Get(addrType).FirstOrDefault());
                break;

            case MailAddressType.Bcc:
                Assert.AreEqual(_addr2a, addrColl.Get(addrType).FirstOrDefault());
                break;

            case MailAddressType.From:
                Assert.AreEqual(_addr3, addrColl.Get(addrType).FirstOrDefault());
                break;

            default:
                Assert.AreEqual(null, addrColl.Get(addrType).FirstOrDefault());
                break;
            }
        }
Ejemplo n.º 4
0
 public MyMailAddressException(
     string message,
     MailAddressType addressType,
     string emailAddress,
     Exception innerException) : base(message, innerException)
 {
     AddressType  = addressType;
     EmailAddress = emailAddress;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Represents the address of an electronic mail sender or recipient for use with a MailMergeMessage.
        /// </summary>
        /// <param name="addrType">MailAddressType of the e-mail address.</param>
        /// <param name="fullMailAddress">A string that contains a full e-mail address, which must include an address part, and may include a display name part, e.g. "Reci Name" &lt;[email protected]&gt;</param>
        /// <param name="displayNameCharacterEncoding">Encoding that defines the character set used for displayName.</param>
        public MailMergeAddress(MailAddressType addrType, string fullMailAddress, Encoding displayNameCharacterEncoding)
        {
            string displayName, address;

            ParseMailAddress(fullMailAddress, out displayName, out address);
            AddrType    = addrType;
            Address     = address;
            DisplayName = displayName;
            DisplayNameCharacterEncoding = displayNameCharacterEncoding;
        }
Ejemplo n.º 6
0
        public MailMergeAddressCollection Get(MailAddressType addrType)
        {
            var addrCol = new MailMergeAddressCollection(ref _mailMergeMessage);

            foreach (var mmAddr in Items.Where(mmAddr => mmAddr.AddrType == addrType))
            {
                addrCol.Add(mmAddr);
            }

            return(addrCol);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Represents the address of an electronic mail sender or recipient for use with a MailMergeMessage.
        /// </summary>
        /// <param name="addrType">MailAddressType of the e-mail address.</param>
        /// <param name="fullMailAddress">A string that contains a full e-mail address, which must include an address part, and may include a display name part, e.g. "Reci Name" &lt;[email protected]&gt;</param>
        /// <param name="displayNameCharacterEncoding">Encoding that defines the character set used for displayName.</param>
        public MailMergeAddress(MailAddressType addrType, string fullMailAddress, Encoding displayNameCharacterEncoding)
        {
            AddrType = addrType;
            DisplayNameCharacterEncoding = displayNameCharacterEncoding;
            MailboxAddress mba;

            if (MailboxAddress.TryParse(displayNameCharacterEncoding?.GetBytes(fullMailAddress), out mba))
            {
                Address     = mba.Address;
                DisplayName = mba.Name;
            }
            else
            {
                Address = fullMailAddress;
            }
        }
Ejemplo n.º 8
0
        public MailMessageBuilder AddRecipient(string address, string name = null, MailAddressType type = MailAddressType.To)
        {
            MailAddress mailAddress = new MailAddress(address, name);

            switch (type)
            {
            case MailAddressType.To:
                To.Add(mailAddress);
                break;

            case MailAddressType.CC:
                CC.Add(mailAddress);
                break;

            case MailAddressType.Bcc:
                Bcc.Add(mailAddress);
                break;
            }

            return(this);
        }
Ejemplo n.º 9
0
        // ------------------------ AddRecipient ----------------------------------
        public void AddRecipient(EmailAddress InAddress, MailAddressType InType)
        {
            try
            {
                switch (InType)
                {
                case MailAddressType.To:
                    mToRecipients.AddRecipient(InAddress);
                    break;

                case MailAddressType.Cc:
                    CCRecipients.AddRecipient(InAddress);
                    break;

                case MailAddressType.Bcc:
                    BCCRecipients.AddRecipient(InAddress);
                    break;
                }
            }
            catch (Exception e)
            {
                throw new MailException("Exception in AddRecipient: " + e.ToString( ));
            }
        }
Ejemplo n.º 10
0
 public string ToString(MailAddressType addrType, object dataItem)
 {
     return(string.Join(", ", Get(addrType).Select(at => at.GetMailAddress(_mailMergeMessage.SmartFormatter, dataItem).ToString())));
 }
Ejemplo n.º 11
0
 public IEnumerable <MailMergeAddress> Get(MailAddressType addrType)
 {
     return(Items.Where(mmAddr => mmAddr.AddrType == addrType));
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Method to formatmail addresses by using address type, mail message and address value
        /// </summary>
        /// <param name="emailAddresses">email addresses separated with ; in case of multiple address</param>
        /// <param name="mailName">to address names</param>
        /// <param name="mailMessage">mail message instance</param>
        /// <param name="addressType">mail address type</param>
        private void ManageMailMessageAddress(string emailAddresses, string mailName, MailMessage mailMessage, MailAddressType addressType)
        {
            if (mailMessage == null || String.IsNullOrEmpty(emailAddresses))
            {
                return;
            }
            if (mailName == null)
            {
                mailName = string.Empty;
            }
            string[] addressList = emailAddresses.Split(new char[] { ';', ',' });
            switch (addressType)
            {
            //if address type provided is to address
            case MailAddressType.ToAddress:
                if (addressList.Length > 1)
                {
                    addressList.ToList().ForEach(address =>
                    {
                        if (!String.IsNullOrEmpty(address))
                        {
                            mailMessage.To.Add(new MailAddress(address));
                        }
                    });
                }
                else
                {
                    mailMessage.To.Add(new MailAddress(addressList[0], mailName));
                }
                break;

            //if address type provided is cc address
            case MailAddressType.CcAddress:
                if (addressList.Length > 1)
                {
                    addressList.ToList().ForEach(address =>
                    {
                        if (!String.IsNullOrEmpty(address))
                        {
                            mailMessage.CC.Add(new MailAddress(address));
                        }
                    });
                }
                else
                {
                    mailMessage.CC.Add(new MailAddress(addressList[0], mailName));
                }
                break;

            //if address type provided is bcc address
            case MailAddressType.BccAddress:
                if (addressList.Length > 1)
                {
                    addressList.ToList().ForEach(address =>
                    {
                        if (!String.IsNullOrEmpty(address))
                        {
                            mailMessage.Bcc.Add(new MailAddress(address));
                        }
                    });
                }
                else
                {
                    mailMessage.Bcc.Add(new MailAddress(addressList[0], mailName));
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Represents the address of a mail sender or recipient for use with a MailMergeMessage.
 /// </summary>
 /// <param name="addrType">MailAddressType of the e-mail address.</param>
 /// <param name="address">A string that contains an e-mail address. Can include display name and address in one string, e.g. "recipient" &lt;[email protected]&gt;.</param>
 public MailMergeAddress(MailAddressType addrType, string address)
     : this(addrType, string.Empty, address)
 {
 }
Ejemplo n.º 14
0
        public static void SendEmail(string to, string subject, string body, string addresses, MailAddressType addressType)
        {
            MailAddress from = From;
            string      bcc  = string.Empty;

            if (MailAddressType.From == addressType)
            {
                from = new MailAddress(addresses);
            }
            else
            {
                bcc = addresses;
            }

            SendEmail(to, subject, body, from, bcc);
        }
Ejemplo n.º 15
0
        public void AddRecipient(string InAddress, MailAddressType InType)
        {
            EmailAddress email = new EmailAddress(InAddress);

            AddRecipient(email, InType);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Represents the address of an electronic mail sender or recipient for use with a MailMergeMessage.
 /// </summary>
 /// <param name="addrType">MailAddressType of the e-mail address.</param>
 /// <param name="address">A string that contains an e-mail address.</param>
 /// <param name="displayName">A string that contains the display name associated with address. This parameter can be null.</param>
 public MailMergeAddress(MailAddressType addrType, string address, string displayName)
     : this(addrType, address, displayName, Encoding.Default)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Represents the address of an electronic mail sender or recipient for use with a MailMergeMessage.
 /// </summary>
 /// <param name="addrType">MailAddressType of the e-mail address.</param>
 /// <param name="address">A string that contains an e-mail address.</param>
 /// <param name="displayName">A string that contains the display name associated with address. This parameter can be null.</param>
 public MailMergeAddress(MailAddressType addrType, string displayName, string address)
 {
     AddrType    = addrType;
     Address     = address;
     DisplayName = displayName;
 }
Ejemplo n.º 18
0
 public MailAddress(string address, MailAddressType addressType)
 {
     Address     = address;
     AddressType = addressType;
 }