Solved

Sending mail with vb.net (VSS2013) using gmail

Posted on 2014-11-12
3
585 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

778 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