Subscribe to Subscribers
Talk to Webmaster Tony John

Resources » .NET programming » Visual Studio

Sending email from an application using VB.NET


Posted Date:     Category: Visual Studio    
Author: Member Level: Silver    Points: 10


Here is a small piece of code which can be used to send an email from an application using VB.NET. You can create a new form and add 4 labels to it and 4 text boxes to it. The labels can be named as From, To, Subject and Message respectively. Corresponding text boxes are also added and kept in position. The last text box can be made multiline. (In the Properties.)



 


Sending email from an application using VB.NET



Here is a small piece of code which can be used to send an email from an application using VB.NET.

You can create a new form and add 4 labels to it and 4 text boxes to it. The labels can be named as From, To, Subject and Message respectively.

Corresponding text boxes are also added and kept in position. The last text box can be made multiline. (In the Properties.)

Add a Button labelled 'Send'

In the code part of the Form, add :


Imports System.Net.Mail


Then add the following code :



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim smtpServer As New SmtpClient()
Dim mail As New MailMessage()
smtpServer.Credentials = New Net.NetworkCredential("abc@gmail.com", "password123")
'using Gmail
smtpServer.Port = 587
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress("abc@gmail.com", TextBox1.Text)
mail.To.Add(TextBox2.Text)
mail.Subject = TextBox3.Text
mail.Body = TextBox4.Text
smtpServer.Send(mail)
Me.Close()

End Sub


In this part smtpServer.Credentials = New Net.NetworkCredential("abc@gmail.com", "password123")

your gmail id and password should be given.

Try this.

I have attached the form design.

NB : I got this with gmail only. I tried some other mail and it did not work. If someone else know, please comment on this article.

Attachments

Sending email from an ...





Did you like this resource? Share it with your friends and show your love!


Responses to "Sending email from an application using VB.NET"
Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: ValidatingEditor in Xtragrid in VB.NET
    Previous Resource: Example of multithreading in VB.NET
    Return to Resources
    Post New Resource
    Category: Visual Studio


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Sending email from an application using VB.NET  .  
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.