How to send a gmail email in vb.net?

by tressie.damore , in category: Third Party Scripts , 9 days ago

How to send a gmail email in vb.net?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , 8 days ago

@tressie.damore 

To send a Gmail email in VB.Net, you will need to use the System.Net.Mail namespace to create a SMTP client and send the email through Gmail's SMTP server. Here is an example code snippet that demonstrates how to send an email using Gmail SMTP server in VB.Net:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
Imports System.Net.Mail

Module Module1

    Sub Main()
        Dim smtpServer As New SmtpClient("smtp.gmail.com")
        smtpServer.Port = 587
        smtpServer.Credentials = New System.Net.NetworkCredential("[email protected]", "your_password")
        smtpServer.EnableSsl = True

        Dim mail As New MailMessage()
        mail.From = New MailAddress("[email protected]")
        mail.To.Add("[email protected]")
        mail.Subject = "Test Email"
        mail.Body = "This is a test email sent from VB.Net"

        smtpServer.Send(mail)

        Console.WriteLine("Email Sent!")
    End Sub

End Module


Make sure to replace "[email protected]" and "your_password" with your own Gmail email address and password. Additionally, replace "[email protected]" with the email address of the recipient you want to send the email to.


You may also need to enable access for less secure apps in your Gmail account settings in order to send emails using this method.