How to send mail in VB .net using System.Net.Mail (SMTP)

In .net we have special namespace called System.Net.Mail. It contains classes used to send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery.

There are three main classes under this namespace.
MailMessage: This class represents the content of a mail message.
SmtpClient: This helps us to transmit emails to the SMTP host (Server) that we specify
Attachment: We all know what is attachment is, this class helps us to create mail attachments.

There are many methods and properties under these three classes.
If you want to know more about it then Click here.

In below post, I will be explaining you a simple and basic methods which we can use to send mails. Of-course later on if you want you can add some more advanced features to it.

1. We have to import below namespace first.

2. Create an object of SmtpClient class

3. Create an object of MailMessage class and using it we will be adding FromToCCBccSubjectMail Body and Attachments.

Please refer below statements one by one.

4. We can attach multiple files with the mail. For that you have to first create attachment object specifying file full path and then use same attachment object with mail.

Dim attachement As New System.Net.Mail.Attachment("C:\tmp\Attachment_file.txt")

5. Few more options available like we can also set priority of mail and also we can send mail as HTML or RichText.

6. Finally, after everything is done, we just have to use same mail object which we have used to create Mail Messages to send mail.

If anyone wants code for this sample application then please let me know your mails id. I will directly send it to you. Enjoy!

Related Posts Plugin for WordPress, Blogger...
Powered by Blogger