Imports System.Web
Imports System.IO
Imports System.Net.Mail
Imports System.Net.Mail.Attachment
Imports System.Runtime
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMail("alvikashif29@yahoo.com", "alvi_kashif@rocketmail.com", "Test Email", "Vb .net Appliction sent this mail", "smtp.gmail.com", False, 465, , "alvikashif29@gmail.com", "xxxxxxxxx")
End Sub
Public Sub SendMail(ByVal [From] As String, ByVal [To] As String, _
ByVal Subject As String, ByVal Body As String, ByVal MailServer _
As String, Optional ByVal IsBodyHtml As Boolean = True, _
Optional ByVal MailPort As Integer = 25, _
Optional ByVal Attachments() As String = Nothing, Optional _
ByVal AuthUsername As String = Nothing, Optional ByVal _
AuthPassword As String = Nothing)
Dim MailClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient(MailServer, MailPort)
Dim MailMessage = New System.Net.Mail.MailMessage([From], [To], Subject, Body)
MailMessage.IsBodyHtml = IsBodyHtml
If (AuthUsername IsNot Nothing) AndAlso (AuthPassword IsNot Nothing) Then
MailClient.UseDefaultCredentials = False
MailClient.EnableSsl = True
MailClient.Credentials = New System.Net.NetworkCredential(AuthUsername, AuthPassword)
End If
If (Attachments IsNot Nothing) Then
For Each FileName In Attachments
MailMessage.Attachments.Add(New System.Net.Mail.Attachment(FileName))
Next
End If
MailClient.Send(MailMessage)
MessageBox.Show("mail sent")
End Sub
End Class
This my code on a new window form with a button on it on click event the sendmail is called with appropriate parameters but when running it an exception occurs
"The operation has timed out"
I am using my gmail account
the smtp server is = smtp.gmail.com
and the port for ssl is 465
(now dont tell me to use 587 as the port because it also does not works. It gives an error
"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 out of this situation please.