Steve Smith's Blog

Musings on Software and the Developer Community

Sending Mail via GMail with AspNetEmail and .NET

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, I’d 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 couldn’t 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 Dave’s tools at AdvancedIntellect.com.  He’s been doing this stuff for nearly 10 years now and even owns the leading help web sites for SystemNetMail and SystemWebMail problems.

    kick it on DotNetKicks.com

Monday, 26 January 2009

Comments

 avatar

Benjiiim said on 27 Jan 2009 at 12:08 PM

Hello,

What is the advantage of this method against the "classic method" that you can find here for example : dotnetguts.blogspot.com/.../send-email-from ?

Cheers!


ssmith avatar

ssmith said on 27 Jan 2009 at 12:30 PM

Only difference is that I'm using AspNetEmail, a commercial product. If you're using System.Net.Mail, that post looks like it has what you need.


 avatar

vinkas said on 09 Feb 2009 at 4:31 AM

hi

its nice article.

its very useful to me


 avatar

nazeemtuticorin said on 31 May 2009 at 1:48 AM

it is very useful