Webnode

VB - Sending emails

In this tutorial you will learn how you can send emails using Visual Basic 2010.

Start by creating a new project, and call it Emailer or something like that.

Add some controls to your form to make it look like this:

2x Label
2x Textbox
1x Button

Double click your button to edit the codes behind your button.
First of all, we need to import a class..

Imports System.Net.Mail

Now, you need to add some codes to your button1_Click event:

 

Try
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New Net.NetworkCredential("username@gmail.com", "password") 'gmail email address and its password
            SmtpServer.Port = 587 'The port
            SmtpServer.Host = "smtp.gmail.com" 'Host is gmail
            mail = New MailMessage()
            mail.From = New MailAddress("username@gmail.com") 'Same email addres as used above
            mail.To.Add("TOADDRESS") 'to e.g. blah@blah.com
            mail.Subject = TextBox1.Text 'This is the subject
            mail.Body = TextBox2.Text 'This is the message
            SmtpServer.Send(mail)
            MsgBox("mail send")
        Catch ex As Exception
            MsgBox(ex.ToString)
End Try
Remeber to change your credentials or otherwise this wont work.
I hope you found this tutorial useful.
You can download the source codes here:

Topic: VB - Sending emails

Date: 20/07/2013

By: peter,please

Subject: answer

vin var me

Reply

—————

Date: 08/05/2013

By: tlk

Subject: coding

showing error

Reply

—————

Date: 07/04/2013

By: coder

Subject: need help!

How can I make it automatically send a message I've chosen to the person who uses the program? I'm making a huge project that you need to register to.

Reply

—————

Date: 23/12/2012

By: alaa

Subject: error

it shows this error

Failure sending email.

Reply

—————

Date: 30/11/2012

By: Sr. Vismaya

Subject: Timed out problem

It shows this error. Please help me

System.Net.Mail.SmtpException:The operation has timed out at System.Net.Mail.SmtpClient.Send(MailMessage message) at NirmalaLibrary.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\jesus\Documents\Visual Sudio 2012\Projects\NirmalaLibrary\NirmalaLibrary\Form1.vb:line17

Reply

—————

Date: 04/11/2012

By: Ulf

Subject: Thanks a lot

I works

Reply

—————

Date: 18/10/2012

By: pp

Subject: pp

pp

Reply

—————

Date: 25/09/2012

By: df

Subject: dsf

sdf

Reply

—————

Date: 31/08/2012

By: ssas

Subject: sasas

sasasas

Reply

—————