Esempio n. 1
0
 protected bool Equals(MailMergeAddress other)
 {
     return(AddrType == other.AddrType && string.Equals(Address, other.Address) && string.Equals(DisplayName, other.DisplayName) && Equals(DisplayNameCharacterEncoding, other.DisplayNameCharacterEncoding));
 }
Esempio n. 2
0
        /// <summary>
        /// Prepares all recipient address and the corresponding header fields of a mail message.
        /// </summary>
        private void AddAddressesToMailMessage(MimeMessage mimeMessage, object dataItem)
        {
            _badMailAddr.Clear();

            MailMergeAddress testAddress = null;

            foreach (MailMergeAddress mmAddr in MailMergeAddresses.Where(mmAddr => mmAddr.AddrType == MailAddressType.TestAddress))
            {
                testAddress = new MailMergeAddress(MailAddressType.TestAddress, mmAddr.Address, mmAddr.DisplayName);
            }

            if (Config.StandardFromAddress != null)
            {
                Config.StandardFromAddress.Address = SearchAndReplaceVars(Config.StandardFromAddress.Address, dataItem);
                Config.StandardFromAddress.Name    = SearchAndReplaceVars(Config.StandardFromAddress.Name, dataItem);
                mimeMessage.From.Add(Config.StandardFromAddress);
            }

            foreach (var mmAddr in MailMergeAddresses)
            {
                try
                {
                    MailboxAddress mailboxAddr;
                    // use the address part the test mail address (if set) but use the original display name
                    if (testAddress != null)
                    {
                        testAddress.DisplayName = mmAddr.DisplayName;
                        mailboxAddr             = testAddress.GetMailAddress(SmartFormatter, dataItem);
                    }
                    else
                    {
                        mailboxAddr = mmAddr.GetMailAddress(SmartFormatter, dataItem);
                    }

                    SmartFormatter.MissingVariables.ToList().ForEach(f => _badVariableNames.Add(f));

                    if (Config.IgnoreIllegalRecipientAddresses && mailboxAddr == null)
                    {
                        continue;
                    }

                    switch (mmAddr.AddrType)
                    {
                    case MailAddressType.To:
                        mimeMessage.To.Add(mailboxAddr);
                        break;

                    case MailAddressType.CC:
                        mimeMessage.Cc.Add(mailboxAddr);
                        break;

                    case MailAddressType.Bcc:
                        mimeMessage.Bcc.Add(mailboxAddr);
                        break;

                    case MailAddressType.ReplyTo:
                        mimeMessage.ReplyTo.Add(mailboxAddr);
                        break;

                    case MailAddressType.ConfirmReadingTo:
                        mimeMessage.Headers.RemoveAll(CConfirmReading);
                        mimeMessage.Headers.RemoveAll(HeaderId.DispositionNotificationTo);
                        mimeMessage.Headers.Add(CConfirmReading, mailboxAddr.Address);
                        mimeMessage.Headers.Add(HeaderId.DispositionNotificationTo, mailboxAddr.Address);
                        break;

                    case MailAddressType.ReturnReceiptTo:
                        mimeMessage.Headers.RemoveAll(HeaderId.ReturnReceiptTo);
                        mimeMessage.Headers.Add(HeaderId.ReturnReceiptTo, mailboxAddr.Address);
                        break;

                    case MailAddressType.Sender:
                        mimeMessage.Sender = mailboxAddr;
                        break;

                    case MailAddressType.From:
                        mimeMessage.From.Add(mailboxAddr);
                        break;
                    }
                }
                catch (FormatException)
                {
                    _badMailAddr.Add(mmAddr.ToString());
                }
            }
        }