Web Scripting
Active Server Pages
Java
Python
Online Tools
Click Here


Home

What's New

Articles

Code Downloads

Code Snippets

Message boards

Links
Tool Box

Books

Mailing List
Receive free code snippets and notices when this site is updated.

Contact

Sending mail using SMTP

In this tutorial you will learn how to send mail using the standard Simple Mail Transport Protocol with out using any 3rd party DLLs or OCXs.

This example uses the Microsoft Winsock control so you will need Visual Basic Pro Version 5 or above.

Step 1.
Creating a new program and adding components

Start VB and select Standard EXE.  This program uses the Winsock control so select Components... from the Project menu.  Make sure there is a check next to "Microsoft Winsock Control 5.0" and click on OK.

Step 2.
Creating the user interface

Add the following controls to a form as shown in the picture above.

Control Type Name Purpose
Text box txtToEmailAddress The address that the message is being sent to.
Text box txtFromEmailAddress Sender's (your) email address
Text box txtFromName Sender's name
Text box txtEmailSubject Subject of the email
Text box txtEmailServer The name of the SMTP server.
Text box txtMessage The Body of the Email Messages
Command Button CmdSendMail Click this to send the email.
Label StatusTxt Displays what's happening.
Winsock Control Winsock1 Used to send the message.

Step 3.
Add the code

Now we are ready to add the code to send the mail. Just paste the code below into the Declarations section of the form.

 

Step 4.
Running the program

Now press F5 to run the program enter the address of your SMTP server and the receipt's address in the To box, fill in the other fields if you want and press send and your message should be on its way to it's destination.

Download this project

Tell a friend about this article