ASP Snippets

Categories






Alerts

Free Alerts

Your email will always be
private and will not be shared.




Follow us on twitter.




Zoom In | Zoom Out


Author is awarded Most Valuable Professional award by Microsoft ASP/ASP.Net

Send Email using VB.Net

Author:Mudassar Khan


Namespaces


The following Namespaces need to be imported in order to send emails


Imports System.Net.Mail


Imports System.Net




MailMessage Class Properties


Following are the required properties of the mail message class.



From – Sender’s email address


To – Recipient(s) Email Address


CC – Carbon Copies


BCC – Blind Carbon Copies


Subject – Subject of the Email 


Body – Body of the Email


IsBodyHtml – Specify whether body contains text or HTML mark up.


Attachments – Attachments if Any.


ReplyTo – ReplyTo Email address.



Creating a MailMessage Object


Dim mm As MailMessage = New MailMessage()


mm.From = New MailAddress("sender@gmail.com")


mm.Subject = "Hello"


mm.Body = "<p>This is Body of the Email</p>"


mm.IsBodyHtml = True


mm.To.Add(New MailAddress("recepient@gmail.com"))




SMTP Class Properties


Following are the properties of the SMTP class.


Host – Your SMTP Server


EnableSsl – Specify whether you host accepts SSL Connections.


UseDefaultCredentials – Set to True inorder to allow authentication based on the Credentials of the Account used to send emails


Credentials – Valid login credentials for the SMTP server


Port – Port Number of the SMTP server



Below code describes how the above properties are applied


smtp.Host = "smtp.gmail.com"


smtp.EnableSsl = True


Dim NetworkCred As NetworkCredential = New System.Net.NetworkCredential()


NetworkCred.UserName = "username@gmail.com"


NetworkCred.Password = "xxxxxxxxx"


smtp.UseDefaultCredentials = True


smtp.Credentials = NetworkCred


smtp.Port = 587



Send Email


The method Smtp.Send(..) is used to send the email. See the example below


smtp.Send(mm)



You can download the complete source here.



 

EmailUsingVB.zip (2.87 kb)

Posted: Jan 18 2009, 10:38 by Mudassar Khan | Comments (3) RSS comment feed |
Filed under: VB.Net

Views: 7442
Page copy protected against web site content infringement by Copyscape


If you like this article, help us grow by bookmarking this page on any social bookmarking site.
Bookmark and Share





Comments

Add comment


 

biuquote
  • Comment
  • Preview
Loading




0  +  0  =   










Community News





Web Hosting SpotLight


Consulting


For consulting and work related queries click here.



Advertise


Advertise with us. For more details click here.


Suggestions


Please provide your valuable suggesstions here.

This Site is hosted on

Lunarpages.com Web Hosting