Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sending mail with vb.net (VSS2013) using gmail

Posted on 2014-11-12
3
Medium Priority
?
599 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 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses

971 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