Sending .NET EMail Via smtp.gmail.com

Sending .NET EMail Via smtp.gmail.com

I just finished wrapping up an article on how to send email from within a Windows or Web application with the System.Net.Mail namespace. One of the things I uncovered is that you can send email through the gmail smtp server. Of course you need to have a GMail account first...

Imports System.Net.Mail

'Start by creating a mail message object Dim MyMailMessage As New MailMessage()

'From requires an instance of the MailAddress type MyMailMessage.From = New MailAddress("from_address_here@gmail.com")

'To is a collection of MailAddress types MyMailMessage.To.Add("to_address_here@domain_name_here")

MyMailMessage.Subject = "GMail Test" MyMailMessage.Body = "This is the test text for Gmail email"

'Create the SMTPClient object and specify the SMTP GMail server Dim SMTPServer As New SmtpClient("smtp.gmail.com") SMTPServer.Port = 587 SMTPServer.Credentials = New System.Net.NetworkCredential("account uid", " account pwd") SMTPServer.EnableSsl = True

Try SMTPServer.Send(MyMailMessage) MessageBox.Show("Email Sent") Catch ex As SmtpException MessageBox.Show(ex.Message) End Try

Just thought I'd pass that little tidbit on.

Have a day. :-|

posted on Monday, July 16, 2007 12:17 PM Print

This article is part of the GWB Archives. Original Author: Jim Duffy

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.