[Webinar] Streamline your web hosting managementRegister Today


send email from a gmail account ... vb.net

Posted on 2010-03-24
Medium Priority
Last Modified: 2013-11-26
Does anybody have code that works to send email in vb.net code using an exsisting google email account?

Question by:troyvw
LVL 23

Expert Comment

ID: 28479054
google is a better friend than EE you know.

LVL 20

Expert Comment

ID: 28479504
Or... an even simpler way is to send the mail out through your existing setup.
Just as if you were specifing you@yourcompany.com
Gmail has no SPF records (a record that blocks where email comes from) so if you just set the outbound email to you@gmail.com it will look like it came from gmail.

Author Comment

ID: 28480158
jakethecatuk: I tried your code and got a message that I cannot connect to the remote server.  I tried other code with the same result...
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Accepted Solution

Coralie Crumrine earned 2000 total points
ID: 28481079
Try something like this:
'//GMail Stuff
    Public Sub GmailTest()
        Dim MyMailMessage As New MailMessage
        MyMailMessage.From = New MailAddress("xxxxx@gmail.com")
        MyMailMessage.Body = "This is a test text sent " & Now

        'Dim SMTPServer As New SmtpClient("smtp.gmail.com")
        Dim SMTPServer As New SmtpClient
        SMTPServer.Host = "smtp.gmail.com"
        SMTPServer.Port = 587
        SMTPServer.Credentials = New Net.NetworkCredential("gMailUserName", "gMailPassword")
        SMTPServer.EnableSsl = True

        Inform("message sent")
    End Sub

Open in new window

LVL 23

Expert Comment

ID: 28481169
is port 587 allowed outbound from your PC?

I'm no developer so I can't help much further besides pointing you at a piece of code that is supposed to do what you want.

This is taken from the GMAIL website: -
'...Please note that if your client does not support SMTP authentication, you won't be able to send mail through your client using your Gmail address.

Also, if you're having trouble sending mail but you've confirmed that encyrption is active for SMTP in your mail client, try to configure your SMTP server on a different port: 465 or 587.
LVL 16

Expert Comment

ID: 28482220
try this:
Imports System.Net.Mail
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sEmailAddress As String
        Using email As New System.Net.Mail.MailMessage
            Dim eclient As New System.Net.Mail.SmtpClient
                       Dim basicAuthenticationInfo As New System.Net.NetworkCredential("yourgmailusername", "yourpassword")
            'Put your own, or your ISPs, mail server name onthis next line
            eclient.Host = "smtp.gmail.com"
            sEmailAddress = "youremail@gmail.com"
            email.From = New MailAddress(sEmailAddress)
            eclient.EnableSsl = True
            email.To.Add(New MailAddress("blah@yahoo.com"))
            email.Subject = "gmail code"
            email.Priority = MailPriority.Normal
            email.IsBodyHtml = True
            email.Attachments.Add(New Attachment("c:\gmail.txt"))
            email.Body = "How are you doing? "
            eclient.UseDefaultCredentials = False
            eclient.Credentials = basicAuthenticationInfo

        End Using ' Using email As New System.Net.Mail.MailMessage
    End Sub
End Class

Author Closing Comment

ID: 31706788
This code worked for me

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question