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 :
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("email@example.com", "password123")
smtpServer.Port = 587
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress("firstname.lastname@example.org", TextBox1.Text)
mail.Subject = TextBox3.Text
mail.Body = TextBox4.Text
In this part smtpServer.Credentials = New Net.NetworkCredential("email@example.com", "password123")
your gmail id and password should be given.
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.