1. Computing

Send and Receive EMail using Visual Basic

Three ways to process email in VB6 and VB.NET

By

Question: How do I use Visual Basic to access the HTML code of a website?

The easiest way to do this in VB6 is probably to use the Microsoft MAPI control. MAPI is Messaging Application Programming Interface. Add this to your VB6 project by clicking Project from the top menu, then select Components. Scroll down the list until you find the Microsoft MAPI controls and click the check box to add it.

Using the MAPI control involves two steps:

  1. Establishing a MAPI session

  2. Using MAPI properties and methods

With the MAPI component, you can create and send a message, include a file attachment, verify the recipient's email address against the email system's address book and lots more. For example, this statement (with the proper supporting code) can sign on to a MAPI Session.


MAPISession1.SignOn

VB.NET EMail

In VB.NET, you can do essentially the same thing (but with more power and flexibility) using System.Net.Mail. The MailMessage class in that namespace represents the content of a mail message. The SmtpClient class transmits email to an SMTP host and you can create mail attachments using the Attachment class. You can find example code at Microsoft's MSDN site.

These objects will probably do the job for you, but if you need to go to a lower level, search for SMTP, the Simple Mail Transfer Protocol, and POP3, the Post Office Protocol version 3.

An alternative way to do the job is to take advantage of the Microsoft Outlook objects using automation. Add a Reference to the Microsoft Outlook object library to your VB.NET project. Using this method, the Microsoft.Office.Interop.Outlook.Application class represents the entire application, the MAPIFolder class represents a folder that contains e-mail messages or other items, and the MailItem class represents an e-mail message.

See More About
  1. About.com
  2. Computing
  3. Visual Basic
  4. Quick Tips
  5. Using EMail Objects in Visual Basic - How to Send and Receive EMail in VB

©2014 About.com. All rights reserved.