Mail |
public abstract void Connect( string host, int port = 0, SecureSocketOptions options = SecureSocketOptions.Auto, CancellationToken cancellationToken = default )
Exception | Condition |
---|---|
ArgumentNullException | host is null. |
ArgumentOutOfRangeException | port is not between 0 and 65535. |
ArgumentException | The host is a zero-length string. |
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 ()) { client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect); client.Authenticate ("username", "password"); client.Send (message); client.Disconnect (true); } }