0

I have an application that sends an e-mail via outlook. My code receives a mail recipient list from an another program. The issue is that I need to remove one of the e-mail addresses before sending the e-mail.

This is what I receive, with recipients already populated.

  Outlook.MailItem mail = _otApp.CreateItem(Outlook.OlItemType.olMailItem);

I know I can add new recipients using the line below,

  mail.Recipients.Add("joe.blogs@someaddress.com");

I also know there is a mail.Recipients.Remove method. This method though requires me to know the position of the e-mail address I need to remove which I do not know.

mHelpMe
  • 6,336
  • 24
  • 75
  • 150
  • This program might help you to gain more insight into the situation: help http://www.dimastr.com/outspy/home.htm – RenniePet Nov 27 '14 at 10:38

1 Answers1

1

You can use Recipient.Delete. Something like the following (off the top of my head):

foreach (var recipient in mail.Recipients)
{
   if (string.Compare(recipient.Address, "joe.blogs@someaddress.com", true) == 0)
    {
        recipient.Delete();
        break;
    }
}
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78