Mail |
public void Connect( Uri uri, CancellationToken cancellationToken = default )
Exception | Condition |
---|---|
ArgumentNullException | The uri is null. |
ArgumentException | The uri is not an absolute URI. |
ObjectDisposedException | The MailService has been disposed. |
InvalidOperationException | The MailService is already connected. |
OperationCanceledException | The operation was canceled via the cancellation token. |
SocketException | A socket error occurred trying to connect to the remote host. |
IOException | An I/O error occurred. |
ProtocolException | A protocol error occurred. |
public static void SendMessage (MimeMessage message) { using (var client = new SmtpClient ()) { // Note: since GMail requires SSL at connection time, use the "smtps" // protocol instead of "smtp". var uri = new Uri ("smtps://smtp.gmail.com:465"); client.Connect (uri); client.Authenticate ("username", "password"); client.Send (message); client.Disconnect (true); } }