Hi All
I am trying hard from the past 2 days to Send mail to my gmail account. But I am not able to do so
Only Exception i am getting is "Failure sending mail." Please Help me out
If i am giving wrong username and password then it is giving the exception
" The SMTP server requires a secure connection or the client was not authenticated.
The server response was: 5.5.1 Authentication Required. Learn more at"
I have posted my account below.
Public Sub SendMail()
Try
Dim strTo As String = "xxxxxxxxx@gmail.com"
Dim strFrom As String = "xxxxxx@gmail.com"
Dim strSubject As String = "Mail Testing"
Dim strBody As String = "Mail Testing . Do Not Reply"
Dim fileName As String = ""
'create new mail message
Dim mailMessage As New System.Net.Mail.MailMessage(AppSettings("From"), strTo, strSubject, strBody)
'create smtpclient with exchangeserver Ip and port number as 25
Dim mailClient As New System.Net.Mail.SmtpClient()
If AppSettings("ServerName") <> "" Then
mailClient.Host = AppSettings("ServerName")
mailClient.Port = AppSettings("smtpPort")
If (AppSettings("smtpUser").Length > 0) Then
mailClient.Credentials = New System.Net.NetworkCredential(AppSettings("smtpUser"), AppSettings("smtpPassword"))
End If
End If
'provide username and password form which the mail has to be sent
'Dim mailCredentials As New System.Net.NetworkCredential("Flightreport@globaleliteinc.com", "FR@tp123")
mailClient.UseDefaultCredentials = False
mailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
mailClient.EnableSsl = True
mailClient.Send(mailMessage)
Catch ex As Exception
Throw New Exception("SendMail() Error: " & ex.Message)
End Try
End Sub
===============================================================
And My Webconfig file is:
<add key="ServerName" value="smtp.gmail.com"/>
<add key="smtpUser" value="xxxxxxxxx@gmail.com"/>
<add key="smtpPassword" value="abcdefgh"/>
<add key="smtpPort" value="587" />
<add key="From" value="xxxxxxxx@gmail.com"/>