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

MailBee.NET Objects MailBee.NET Objects MailBee.NET Objects .NET .NET .NET SMTP SMTP SMTP SSL SSL SSL Gmail Gmail Gmail connection connection connection problem problem problem send mail send mail send mail
Gmail accepts only secure SSL connections, and thus you should use MailBee.NET SMTP component in SSL mode.

C#:
using MailBee;
using MailBee.SmtpMail;
using MailBee.Security;

...
Smtp mailer = new Smtp();
SmtpServer server = new SmtpServer("smtp.gmail.com", "gmail-login", "gmail-password");
server.SslMode = SslStartupMode.UseStartTls;
mailer.SmtpServers.Add(server);
mailer.From.Email = "user@gmail.com";
mailer.To.Add("kathy@company.com");
mailer.Subject = "Report";
mailer.BodyPlainText = "The report contents";
mailer.Send();


VB.NET:
Imports MailBee
Imports MailBee.SmtpMail
Imports MailBee.Security

...
Dim mailer As New Smtp
Dim server As SmtpServer = New SmtpServer(smtp.gmail.com", "gmail-login", "gmail-password")
server.SslMode = SslStartupMode.UseStartTls
mailer.SmtpServers.Add(server)
mailer.From.Email = "user@gmail.com"
mailer.To.Add("kathy@company.com")
mailer.Subject = "Report"
mailer.BodyPlainText = "The report contents"
mailer.Send()


You'll also need to make sure your license key is specified in the config file or in the code.
Back to articles list