More .NET libraries
-
Rebex Mail Pack
IMAP, MS Graph, EWS, POP3, SMTP, MIME, S/MIME, MSG
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Easy-to-use API
On this page:
A typical SMTP session goes through the following steps:
- Connect to an SMTP server.
- Validate the server certificate (this is done automatically by default, but you can perform the validation yourself).
- Log in - if required, authenticate with a user name and password or using a certificate.
- Send e-mail messages, etc.
- Disconnect.
Sending email using SMTP
The following code sends a simple mail message:
string sender = "my_account@gmail.com"; string recipient = "to@example.org"; string subject = "Test"; string body = "Hello World!"; // create SMTP client instance using (var smtp = new Rebex.Net.Smtp()) { // connect to Gmail SMTP server smtp.Connect(gmail_smtp_hostname, SslMode.Explicit); // authenticate with your email address and password smtp.Login(sender, password); // send mail smtp.Send(sender, recipient, subject, body); // disconnect (not required, but polite) smtp.Disconnect(); }
Dim sender As String = "my_account@gmail.com" Dim recipient As String = "to@example.org" Dim subject As String = "Test" Dim body As String = "Hello World!" ' create SMTP client instance Using smtp = New Rebex.Net.Smtp() ' connect to Gmail SMTP server smtp.Connect("smtp.gmail.com", SslMode.Explicit) ' authenticate with your email address and password smtp.Login(sender, password) ' send mail smtp.Send(sender, recipient, subject, body) ' disconnect (not required, but polite) smtp.Disconnect() End Using
Sending e-mail can be even easier. Check out Sending e-mail with a single line of code.
Back to feature list...