Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse a MailMessage object and SmtpMail.Send to send email in Visual Basic .NET
DescriptionThis example shows how to use a MailMessage object and SmtpMail.Send to send email in Visual Basic .NET
Keywordsemail, mail, MailMessage, SmtpMail.Send, IExplore, VB.NET
CategoriesOffice, Software Engineering
 
Note that this project requires a reference to System.Web.dll and imports System.Web.Mail.

Create a MailMessage object and set its properties to define the mail message.

If you are behind a firewall, set SmtpMail.SmtpServer to define the mail server.

Then use SmtpMail.Send to send the email.

 
Dim mail_message As New MailMessage
With mail_message
    If txtTo.Text.Trim.Length > 0 Then .To = txtTo.Text.Trim
    If txtFrom.Text.Trim.Length > 0 Then .From = _
        txtFrom.Text.Trim
    If txtCc.Text.Trim.Length > 0 Then .Cc = txtCc.Text.Trim
    If txtBcc.Text.Trim.Length > 0 Then .Bcc = _
        txtBcc.Text.Trim
    If txtSubject.Text.Trim.Length > 0 Then .Subject = _
        txtSubject.Text.Trim
    If txtBody.Text.Trim.Length > 0 Then .Body = _
        txtBody.Text.Trim

    Select Case cboPriority.Text
        Case "Low"
            .Priority = MailPriority.Low
        Case "Normal"
            .Priority = MailPriority.Normal
        Case "High"
            .Priority = MailPriority.High
    End Select

    .BodyEncoding = System.Text.Encoding.Default
End With

' If you're behind a firewall, define your email server.
'SmtpMail.SmtpServer = "MyCompany.Server.com"

' Send the email.
SmtpMail.Send(mail_message)
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated