send email from a gmail account ...

Does anybody have code that works to send email in code using an exsisting google email account?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

google is a better friend than EE you know.
Or... an even simpler way is to send the mail out through your existing setup.
Just as if you were specifing
Gmail has no SPF records (a record that blocks where email comes from) so if you just set the outbound email to it will look like it came from gmail.
troyvwAuthor Commented:
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...
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Coralie CrumrineCommented:
Try something like this:
'//GMail Stuff
    Public Sub GmailTest()
        Dim MyMailMessage As New MailMessage
        MyMailMessage.From = New MailAddress("")
        MyMailMessage.Body = "This is a test text sent " & Now

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

        Inform("message sent")
    End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
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 = ""
            sEmailAddress = ""
            email.From = New MailAddress(sEmailAddress)
            eclient.EnableSsl = True
            email.To.Add(New MailAddress(""))
            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
troyvwAuthor Commented:
This code worked for me
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.