Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

Here I have problem when send a email to a specific person using g-mail. Actually my project is copy a excel file from a location and send to a specific person. The file is successfully copy, but the email is cannot be send. a message box is appear, which is show "quot;System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. the server response was:5.7.0 Must issue a STARTTLS command first. qh5sm9940329pbb.71 - gsmtp""

the code were I used is:

VB
Sub Main()
    CopyFile = "\\192.168.5.1\fbar\TOOLS\ProbingApps\ProbingSystem\testMail.xlsx"

    MyHour = Format(Now, "hh")
    MyMinutes = Format(Now, "mm")
    MySec = Format(Now, "ss")
    MyDate = Format(Now, "dd")
    MyMonth = Format(Now, "MM")
    myYear = Format(Now, "yyyy")
    Mydirectory = "C:\Users\Thaneskumar\Desktop\test2\"
    MyExtension = ".xlsx"
    MyFileName = Mydirectory + MyHour + MyMinutes + MySec + "_" + MyDate + MyMonth + "_" + myYear + MyExtension

    CopyTo = MyFileName

    If System.IO.File.Exists(CopyFile) = True Then

        System.IO.File.Copy(CopyFile, CopyTo)
        MsgBox("File Copied")

    End If
    automail()
    MsgBox("Mail send")

End Sub
Public Sub automail()
    Try
        Dim SmtpServer As New SmtpClient()
        Dim mail As New MailMessage()
        SmtpServer.Credentials = New  _
    Net.NetworkCredential("cgthanes44@gmail.com", "******")
        SmtpServer.Port = 587
        SmtpServer.Host = "smtp.gmail.com"
        mail = New MailMessage()
        mail.From = New MailAddress("cgthanes44@gmail.com")
        mail.To.Add("cgthanes33@yahoo.com")
        mail.Subject = "Test Mail"
        Dim attach As New Attachment(MyFileName)
        mail.Attachments.Add(attach)
        mail.Body = "This is for testing SMTP mail from GMAIL"
        SmtpServer.Send(mail)
        MsgBox("mail send")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try

End Sub


Can anyone help me....

Thanks.

Regards,
Thanes
Posted

1 solution

First of all make sure that the credentials are correct.

Then refer my past answer - sending email to gmail from asp.net[^]. You will find a complete working code.

Looking at the code, I see that the following lines are missing.
C#
client.UseDefaultCredentials = false;
client.EnableSsl = true; //Gmail works on Server Secured Layer
 
Share this answer
 
Comments
CgKumar 7-Sep-15 0:56am    
Yes. Thanks. But now I m have other error. Which is "System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. the server response was:5.5.1 authentication required". Please Help me...
Do you have a 2-step verification on for the account whose credentials you are using?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900