|Whats New | Articles | Message Board | Links | Code Snippets | Code Downloads | Toolbox | Books|
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.
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.
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.
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.
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
Visual Basic | ASP
| Web Scripting