MailBee. NET Objects Tutorials

How can I send e-mail through Gmail with C# or VB.NET

Gmail by default restricts external access via SMTP and IMAP. You need to enable it in Gmail account settings. You also need to enable "Less secure apps" to make it possible to authenticate with a login/password. The option name is misleading, they are secure enough. Google just assumes that any authentication which involves login/password exchange is insecure (despite that the transmission channel is TLS-secured).

If it's not an option to enable "Less secure apps", you'll need to use OAuth 2.0 authentication: OAuth 2.0 in Windows, .NET Core, and ASP.NET MVC apps

If it's OK to use login/password authentication, that's how:


using MailBee;
using MailBee.SmtpMail;

Smtp mailer = new Smtp();
SmtpServer server = new SmtpServer("", "gmail-login", "gmail-password");
mailer.From.Email = "";
mailer.Subject = "Report";
mailer.BodyPlainText = "The report contents";


Imports MailBee
Imports MailBee.SmtpMail

Dim mailer As New Smtp
Dim server As SmtpServer = New SmtpServer("", "gmail-login", "gmail-password")
mailer.From.Email = ""
mailer.Subject = "Report"
mailer.BodyPlainText = "The report contents"

MailBee recognizes "" host name and automatically adjusts port number to 465 (dedicated SSL port for SMTP). In case of exceptions, be sure to read the exception text carefully, Gmail often provides self-explaining error messages with clear instructions on what to do. For instance, WEB LOGIN REQUIRED with the link the user must open to confirm access to their account from a new location.