Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sending mail with vb.net (VSS2013) using gmail

Posted on 2014-11-12
3
Medium Priority
?
595 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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