Sending Application Mail through Google Apps (GMail)

I ran into a little gotcha when setting up a new web application to send email through the Google Apps SMTP servers. When you read the Google support documentation on setting up a client to send email through their SMTP server you will see there are 2 options SSL, TSL with a different port for each.
When writing the C# code to send the email there is an option to on the .Net SmtpClient object called ‘EnableSsl’. You of course need to set this to true but the gotcha comes in when you setup the SMTP server and port in your web.config file. You would assume since the option ‘EnableSsl’ refers to ‘SSL’ you would need to use port 465 for SSL as outlined by Google in their documentation. But. you would be wrong to assume that and on every call to send an email within your application you will run into a ‘Time Out’.
I don’t know everything about .Net mail but apparently ‘EnableSsl’ doesn’t really mean SSL it means TSL. I say this because as soon as I changed the SMTP server’s port in my web.config from the SSL port of 465 to the TSL port of 587 as outlined by Google my mail sent without issue.
Hopefully this will save someone a lot of time.
Web.config Setup:

      <smtp from="">
        <network host="" password="******" userName="" port="587" />

C# Send Mail Code:

                MailMessage message = new MailMessage();

                message.From = new MailAddress(tbxEmail.Text);
                message.To.Add(new MailAddress(_supportEmail));

                message.Subject = tbxSubject.Text;
                message.IsBodyHtml = false;
                message.Priority = MailPriority.High;
                message.Body = tbxMessage.Text;

                SmtpClient client = new SmtpClient();
                client.EnableSsl = true;

                return true;
            catch (Exception ex)
                ExceptionHandler handler = new ExceptionHandler();
                    "Contact Form Message could not be sent to support email",

Published by

Tim Clark

Experienced Business Owner, Chief Information Officer, Vice President, Chief Software Architect, Application Architect, Project Manager, Software Developer, Senior Web Developer, Graphic Designer & 3D Modeler, University Instructor, University Program Chair, Academic Director. Specialties: Ruby, Ruby on Rails, JavaScript, JQuery, AJAX, Node.js, React.js, Angular.js, MySQL, PostgreSQL, MongoDB, SQL Server, Responsive Design, HTML5, XHTML, CSS3, C#,, Project Management, System Design/Architecture, Web Design, Web Development, Adobe CS6 (Photoshop, Illustrator)

3 thoughts on “ Sending Application Mail through Google Apps (GMail)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s