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
