The SmtpClient Class states that instance members are not thread safe. This can be seen if concurrent calls are made to Send or SendAsync. Both methods will throw a Invali
I'm not sure why using Reflector didn't work for you. If I decompile it, I see the following code:
[HostProtection(SecurityAction.LinkDemand, ExternalThreading=true)]
public Task SendMailAsync(MailMessage message)
{
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
SendCompletedEventHandler handler = null;
handler = delegate (object sender, AsyncCompletedEventArgs e) {
this.HandleCompletion(tcs, e, handler);
};
this.SendCompleted += handler;
try
{
this.SendAsync(message, tcs);
}
catch
{
this.SendCompleted -= handler;
throw;
}
return tcs.Task;
}
As you can see, it's a simple TAP wrapper for SendAsync()
. And if SendAsync()
throws an exception, SendMailAsync()
just rethrows it.
So, the conclusion is that SendMailAsync()
is not thread-safe and that its exceptions are underdocumented.
As a note (since I don't have enough points to comment), the traditional way to write an asynchronous operation was to use the Asynchronous Programming Model (APM), but today we typically use the Task-based Asynchronous Pattern (TAP) with its async/await keywords. And although it's not unusual to see TAP wrappers around APM methods, it's also possible to see APM wrappers around TAP methods.