A set of .NET Framework managed libraries for developing graphical user interfaces.
The SmtpClient class is not recommended as per Microsoft
Use MailKit via NuGet.
C#
using System;
using MailKit.Net.Smtp;
using MailKit;
using MimeKit;
namespace TestClient
{
internal class Program
{
public static void Main(string[] args)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Joey Tribbiani", "******@friends.com"));
message.To.Add(new MailboxAddress("Mrs. Chanandler Bong", "******@friends.com"));
message.Subject = "How you doin'?";
message.Body = new TextPart("plain") {Text = "Hey Chandler, I just wanted to let you know that Monica and I were going to go play some paintball, you in? -- Joey"};
using (var client = new SmtpClient())
{
client.Connect("smtp.friends.com", 587, false);
// Note: only needed if the SMTP server requires authentication
client.Authenticate("joey", "password");
client.Send(message);
client.Disconnect(true);
}
}
}
}
VB
Option Infer On
Imports System
Imports MailKit.Net.Smtp
Imports MailKit
Imports MimeKit
Namespace TestClient
Friend Class Program
Public Shared Sub Main(ByVal args() As String)
Dim message = New MimeMessage()
message.From.Add(New MailboxAddress("Joey Tribbiani", "******@friends.com"))
message.To.Add(New MailboxAddress("Mrs. Chanandler Bong", "******@friends.com"))
message.Subject = "How you doin'?"
message.Body = New TextPart("plain") With {.Text = "Hey Chandler, I just wanted to let you know that Monica and I were going to go play some paintball, you in? -- Joey"}
Using client = New SmtpClient()
client.Connect("smtp.friends.com", 587, False)
' Note: only needed if the SMTP server requires authentication
client.Authenticate("joey", "password")
client.Send(message)
client.Disconnect(True)
End Using
End Sub
End Class
End Namespace