Solved

Sending mail with vb.net (VSS2013) using gmail

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

24 Experts available now in Live!

Get 1:1 Help Now