Solved

Sending mail with vb.net (VSS2013) using gmail

Posted on 2014-11-12
3
582 Views
Last Modified: 2014-11-12
I am trying to send mail using VB.Net and gmail.
I can get the program to work through my regular email provider, but with gmail it fails

The code is as follows:-

 Try
            MailMessage.From = New MailAddress(EmailSender)
            MailMessage.To.Add(New MailAddress("gordon@grxxx.co.uk"))
            MailMessage.CC.Add(New MailAddress(EmailSender)) ' Copy to the sender
            MailMessage.Subject = "Auto-Email from Comtass SQL Potato Trading System"
            MailMessage.Body = "Haulage Advice for Load Card ABC0123"
            Dim SmtpClient As New SmtpClient()
            SmtpClient.Host = "smtp.gmail.com"
            SmtpClient.Credentials = New Net.NetworkCredential(Username, Password)
            SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
            SmtpClient.EnableSsl = True
            SmtpClient.Port = 587
            SmtpClient.Send(MailMessage)
            Label3.Text = "Copy Sent to " & EmailSender
        Catch ex As Exception
            MsgBox("An Error has Occured - " & ex.Message & vbCrLf _
                & " The Email has Not been Succcessful. Please Retry")
        End Try


If I try port 456 the program hangs for a while then comes back with the message "An error has occurred - failure sending mail. The email has not been successful. please re-try"

If I try port 576 it immediately comes back with a  an error  "the SMTP connection requires a secure client or the client was not authenticated "

I'm tearing my hair out!!
0
Comment
Question by:grwallace
  • 2
3 Comments
 
LVL 3

Expert Comment

by:x_bakos
ID: 40437063
Probably will sound funny to you, but do you create an MailMessage object first?

like Dim MailMessage As New MailMessage()

Also, check the settings you have in your gmail account (Settings > Forwarding and POP/IMAP.)
0
 
LVL 3

Accepted Solution

by:
x_bakos earned 500 total points
ID: 40437067
Also, I think that the Username in the

 SmtpClient.Credentials = New Net.NetworkCredential(Username, Password)

line needs to have your complete email address; thus xyz@gmail.com
0
 

Author Closing Comment

by:grwallace
ID: 40437249
Crazy - I was using the client's actual details - they have a separate "send only" address for what we were trying to do. When I tried logging in to it directly it was asking for further verification due to some other details. it worked perfectly on my own Gmail account and will - presumably - work on the customer's account from their ISP/server
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now