Sending Mail via GMail with AspNetEmail and .NET
Posted by: Steven Smith,
on 26 Jan 2009 |
View original | NEW Bookmarked: 0 time(s)
Periodically, I need to send out announcements to a list of emails pulled from a database. This is a pretty common problem, and a long time ago I found RapidMailer from Dave Wanta aka AdvancedIntellect which does a pretty good job and has all the source. However, Id been using it with my web host provided SMTP/POP3 provider for years, but since I recently moved my accounts to Google Apps (for the tons of free storage), I had to figure out how to configure RapidMailer to work with GMail.
After some searching, I found a post by Dave himself describing the necessary pieces for sending mail via GMail and AspNetMail.. Specifically, since Google requires TLS security, or Transport Level Security, it turns out that this is really just a fancy way of saying SSL (Secure Socket Layer). In this post, The code looks pretty much like this:
EmailMessage m = new
EmailMessage( "smtp.gmail.com" );
m.Username = "test@gmail.com";
m.Password = "test";
//create the ssl socket
AdvancedIntellect.Ssl.SslSocket ssl = new AdvancedIntellect.Ssl.SslSocket();
m.LoadSslSocket( ssl );
//logging on the ssl socket
ssl.Logging = true;
ssl.LogPath = "c:\\ssl.log";
//rest of aspNetEmail properties
m.Port = 587;
m.To = "test@123aspx.com";
m.FromAddress = "test@gmail.com";
m.Subject = "test";
m.Body = "test";
m.Logging = true;
m.LogPath = "c:\\email.log";
m.Send();
However, I couldnt get this to compile because my project had no idea what AdvancedIntellect.Ssl.SslSocket was. A little bit more digging yielded the fact that this was a separate DLL, available from AdvancedIntellect.com for free.
Download AdvancedIntellect.Ssl.dll
Once I grabbed the DLL and added a reference to it in my RapidMailer project, everything was happy and I was able to send emails through GMail. The only other thing I had to do was get the program to send attachments, and that turned out to be only a couple more lines of code.
All in all, if you need to do anything in .NET surrounding email, you really should start with Daves tools at AdvancedIntellect.com. Hes been doing this stuff for nearly 10 years now and even owns the leading help web sites for SystemNetMail and SystemWebMail problems.