MailBee.NET Objects 4.0

EmailAddressCollection.Remove Method 

Removes the specified e-mail address from the collection.

public void Remove(
   string email
);

Parameters

email
Actual e-mail address to be deleted (i.e. user@domain.com).

Remarks

If the specified e-mail address appears multiple times in the collection, all such entries will be removed.

To remove the e-mail address from the collection by the index, the developer should use RemoveAt method.

Exceptions

Exception TypeCondition
MailBeeInvalidArgumentExceptionaddress is a null reference (Nothing in Visual Basic).

Example

This sample adds some e-mail addresses into To: field and then removes one of them.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Mime;

MailMessage msg = new MailMessage();

msg.To.Add("user1@domain.com");
msg.To.Add("user2@domain.com", "User 2");
msg.To.Add("user3@domain.com", null, "User 3");

Console.WriteLine(msg.To.ToString());

msg.To.Remove("user2@domain.com");

Console.WriteLine(msg.To.ToString());
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Mime

Dim msg As New MailMessage

msg.To.Add("user1@domain.com")
msg.To.Add("user2@domain.com", "User 2")
msg.To.Add("user3@domain.com", Nothing, "User 3")

Console.WriteLine(msg.To.ToString())

msg.To.Remove("user2@domain.com")

Console.WriteLine(msg.To.ToString())

See Also

EmailAddressCollection Class | MailBee.Mime Namespace | RemoveAt