I just commented out the two for loops and using port 587 it works fine.
--please don't forget to upvote
and Accept as answer
if the reply is helpful--
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Dim Mail As New MailMessage
Mail.Subject = "Sent with VB.net"
Mail.To.Add("******@gmail.com")
Mail.From = New MailAddress("******@gmail.com")
Mail.Body = "Hello from Visual Studio"
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("******@gmail.com", "myPassword")
SMTP.Port = "587"
Dim dirAttach = "C:\MyDocs"
For Each h As String In IO.Directory.GetFiles(dirAttach , "*.jpg", IO.SearchOption.AllDirectories)
For Each t As String In IO.Directory.GetFiles(dirAttach , "*.txt", IO.SearchOption.AllDirectories)
Mail.Attachments.Add(New Attachment(h))
Mail.Attachments.Add(New Attachment(t))
Next
Next
SMTP.Send(Mail)
The above code was working fine few months ago, but today it give me error that SMTP is not supported or it's not secure. Is something has changed or gmail is not supported any more?
I just commented out the two for loops and using port 587 it works fine.
--please don't forget to upvote
and Accept as answer
if the reply is helpful--
Did you create an app password? I just created a new app password for my testing.
https://support.google.com/accounts/answer/185833?hl=en
Also the below worked fine for me as long as the directory exists
Dim dirAttach = "C:\MyDocs"
For Each h As String In IO.Directory.GetFiles(dirAttach , "*.jpg", IO.SearchOption.AllDirectories)
Mail.Attachments.Add(New Attachment(h))
Next
For Each t As String In IO.Directory.GetFiles(dirAttach , "*.txt", IO.SearchOption.AllDirectories)
Mail.Attachments.Add(New Attachment(t))
Next
--please don't forget to upvote
and Accept as answer
if the reply is helpful--