Friday, March 16, 2012

VB Send Email

If you are still working in classic VB, sending email is not as easy as we do in asp.net. Especially for notifications emails are one of the best ways to communicate. Normally the SMTP server will be in separate email hosting server reachable from application server. In this scenario we need to configure CDO to use our SMTP server. Then only the mail relay will be successful.

The function we are discussing will support most of the email functionalities like CC, BCC and attachment.
The function will return the status about sent. Since this function is designed for applications, the related settings can be fetched from settings file rather than changing the code and re compiling to take changes.

Basically the following configurations are necessary before sending mail with CDO object
•  CDO.Message
• CDO.Configuration

This object is used to set the various properties like following

• To
• From
• Subject
• TextBody
• Attachment
• CC
• BCC
Finally we can call the Send method to send the mail. 

This object is used to set the configurations like
• Send using
• SMTP server
• SMTP server port

Please change the respective SMTP server in the "change your SMTP server here" section. Or else you will get the "The transport failed to connect to the server." error message. 

Most of my applications are using this function which needs SMTP Authentication. In order for this function to work, you must have a valid SMTP server with a valid user name and password.

It happened to me that my user account was locked or grey listed once since I have tried several times with bad password. Then the setting won’t work for a while until it gets released. So it is better if you have any doubts, use any utilities which may help to test the email before using this function. So make sure you have valid credentials and information regarding the SMTP server before using this function.


View the original article here

No comments:

Post a Comment