img by Coba

How to Send Email Through a Gmail Account Using aspNetEmail and ASP.NET

I’m a big fan of aspNetEmail – I’ve used six or seven products from AdvancedIntellect through the years and never once have I been unhappy or wished it did more than it does. Great stuff – check it out here: http://www.aspnetemail.com/. I had to figure out today how to post through SSL today so that I could submit an email through one of my GMail accounts. It isn’t necessarily “native” to aspNetEmail to use secure servers but it is trivially easy to get it going. I thought I’d post it here if for no other reason that it would help me remember how to do it later! By the way, the rest of this post assumes you have downloaded aspNetEmail and have a license (it isn’t free but it’s worth the pittance they charge).

To use your Gmail account with aspNetEmail

Step 1: Go download the add-on AdvancedIntellect.Ssl.dll. It’s free and requires no registration

Step 2: Unpack the .zip file and follow the incredibly simple instructions – it’s literally TWO lines of code!

Step 3: Add a reference to both aspNetEmail and AdvancedIntellect.Ssl.dll to your project

Step 4: Code it up!

 
            var mail = new EmailMessage { ValidateAddress = true };
            // Fill in details such as To, From, Body, etc
 
            // Gmail-specific:
            mail.Server = "smtp.gmail.com";
 
            var ssl = new AdvancedIntellect.Ssl.SslSocket();
            mail.LoadSslSocket(ssl);
 
            mail.Port = 587;
            mail.Username = myGmailEmailAddress;
            mail.Password = myGmailPassword;
 
            mail.Send();

The two important lines are:

var ssl = new AdvancedIntellect.Ssl.SslSocket();
mail.LoadSslSocket(ssl);

Super easy – I love AdvancedIntellect :)

And by the way - check out our IT training videos blog while you’re here! We put lots of SQL videos, C# training videos, and more up there all the time.

authors
scott whigham
grant moyle
chad weaver