Sending email from VB

September 2nd, 2007

It's easy to send an email from VB. Create a new console application project in Visual Basic Express. Then paste this code in the Module1.vb file. The code demonstrates the basic steps in constructing a simple email message and sending it.

Imports System.Net.Mail

Module Module1

    Sub Main()
        Dim msg As New MailMessage
        Dim smtp As New SmtpClient

        'define smtp client parameters
        smtp.Host = "your.smtp.server"
        smtp.Port = 587
        smtp.Credentials = New Net.NetworkCredential("your_username", "your_password")

        'define the message
        msg.From = New MailAddress("your_email@server.com", "Your Name")
        msg.To.Add(New MailAddress("someone@somewhere.com", "Someone"))
        msg.Subject = "Test eMail"
        msg.Body = "This is a test email."

        'Send it!
        smtp.Send(msg)

    End Sub

End Module

Posted in Visual Basic | No Comments




No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment



(C) by Virgilio Adriano. All rights reserved. Powered by WordPress.
Entries and comments feeds.
It took 0.375 seconds to load this page.