Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Visual Basic (Classic) FAQ

New Language Features

Automatic Email by Zarcom
Posted: 2 Jul 02 (Edited 30 Oct 02)

I have noticed a few people here in the .Net forums trying to get their systems to automatically email someone.  I have written a class that does this very simply.  All you need to do is set the properties and call the function whenever you want your program to email someone.

To use this class add a new class file called Emailer.vb.  Open the file and overwrite it with the green code found here.

If you are using this function in a VB.NET standalone project then the dll will not be referenced yet.  To reference it do the following.

Go to Project -> Add Reference -> Find System.Web.dll -> Select and OK.

If you check in your references folder in the solution window you should now see an entry for System.Web

 Imports System.Web
Public Class Emailer
    Private mTo As String
    Private mFrom As String
    Private mSubject As String
    Private mBodyFormat As Mail.MailFormat
    Private mSmtpServer As String

#Region " Class Properties "

    Public Property MailTo() As String
            Return mTo
        End Get
        Set(ByVal Value As String)
            mTo = Value
        End Set
    End Property

    Public Property From() As String
            Return mFrom
        End Get
        Set(ByVal Value As String)
            mFrom = Value
        End Set
    End Property

    Public Property Subject() As String
            Return mSubject
        End Get
        Set(ByVal Value As String)
            mSubject = Value
        End Set
    End Property

    Public Property BodyFormat() As Mail.MailFormat
            Return mBodyFormat
        End Get
        Set(ByVal Value As Mail.MailFormat)
            mBodyFormat = Value
        End Set
    End Property

    Public Property SmtpServer() As String
            Return mSmtpServer
        End Get
        Set(ByVal Value As String)
            mSmtpServer = Value
        End Set
    End Property

#End Region

#Region " Class Functions "

    Public Function EmailCust(ByVal Email As String, ByVal msgBody As String) As Boolean
        Dim myMessage As New Mail.MailMessage()
        Dim myMailServer As Mail.SmtpMail
        Dim output As Boolean = True

        myMessage.To = MailTo
        myMessage.From = From
        myMessage.Subject = Subject
        myMessage.BodyFormat = BodyFormat

        myMessage.Body = msgBody
        myMailServer.SmtpServer = SmtpServer
            output = False
            myMessage = Nothing
        End Try

        Return output
    End Function

#End Region

End Class

Hope you like it!

Back to Visual Basic (Classic) FAQ Index
Back to Visual Basic (Classic) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close