I want to send a mail using gmail id, my code is as here under, but its occurred error...please help me out of this issue.
Imports System.Net Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("This will send a mail...")
Try
Dim smtpserver As New SmtpClient()
Dim mail As New MailMessage()
smtpserver.Credentials = New Net.NetworkCredential("myname@gmail.com", "password")
smtpserver.Port = 465
smtpserver.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("myname@gmail.com")
mail.To.Add("to mail id")
mail.Subject = "Test by bharat"
mail.Body = "hello ooooooooooooooooooooooo"
smtpserver.Send(mail)
MsgBox("Mail Sent")
Catch ex As Exception
MsgBox(ex.ToString)
Close()
End Try
End Sub
End Class
You can make a new class called 'Mail'. If you make a class, you don't have to type all of the code again if you want to send more than 1 email.
And then you can make a new object in your code where and when you want to send the email:
Below is an example of sending an email with visual basic 10, First you need to build a form with fields to,from,text,and email_send button now the below code