Smtp ClientExpand Method
Expand a mailing address alias.
Definition
Namespace: MailKit.Net.Smtp
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
The expanded list of mailbox addresses.
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public InternetAddressList Expand(
string alias,
CancellationToken cancellationToken = default
)Parameters
- alias String
- The mailing address alias.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
InternetAddressListThe expanded list of mailbox addresses.
Implements
ISmtpClientExpand(String, CancellationToken)Remarks
Expands a mailing address alias.
Example
C#
public static void ExpandAlias (string alias)
{
using (var client = new SmtpClient ()) {
client.Connect ("smtp.mail-server.com", 465, SecureSocketOptions.SslOnConnect);
client.Authenticate ("username", "password");
var expanded = client.Expand (alias);
Console.WriteLine ($"Expanding the alias '{alias}' results in the following list of addresses:");
foreach (var mailbox in expanded.Mailboxes)
Console.WriteLine ($"* {mailbox}");
client.Disconnect (true);
}
}
Exceptions
| ArgumentNullException | alias is . |
| ArgumentException | alias is an empty string. |
| ObjectDisposedException | The SmtpClient has been disposed. |
| ServiceNotConnectedException | The SmtpClient is not connected. |
| ServiceNotAuthenticatedException | Authentication is required before expanding an alias. |
| OperationCanceledException | The operation has been canceled. |
| IOException | An I/O error occurred. |
| SmtpCommandException | The SMTP command failed. |
| SmtpProtocolException | An SMTP protocol exception occurred. |