Sending email using VBnet and smtp.office365.com

Stéphane Borel 6 Reputation points
2022-02-10T13:36:35.813+00:00

Hello,

I used to send email through our web site using a COM dll and smtp.office365.com. Everything was working so fine. For some little time, now, it doesn't work anymore. No emails are send from our website.
Here is my code :
Is something have change in smtp Microsft ? or in security for sending email through VB net applications ?

Thanks for some help.

Public Function SendEMail(sTo As String, sSubject As String, sBody As String, sFilePath As String) As String

  InitEmailPAram()

  Dim smtpServer As New SmtpClient()

  'smtpServer.UseDefaultCredentials = True
  smtpServer.Credentials = New Net.NetworkCredential(m_Email_from_support, m_Email_Support_Pwd)
  smtpServer.Port = 25
  smtpServer.Host = "smtp.office365.com" '"go2cam-net.mail.protection.outlook.com" 
  smtpServer.EnableSsl = True

  Dim mail As MailMessage = New MailMessage()
  mail.From = New MailAddress(m_Email_from_support)

  Dim emailTo As String = vbNullString
  Dim emailCC As String = vbNullString

  SplitEmAilToAndCC(sTo, emailTo, emailCC)
  mail.To.Add(emailTo)
  If (emailCC <> vbNullString) Then
     mail.CC.Add(emailCC)
  End If

  mail.Subject = sSubject
  sBody = Replace(sBody, vbCrLf, "<br>")
  mail.Body = sBody
  mail.IsBodyHtml = True

  Dim TabPieceJointe() As String
  TabPieceJointe = Split(sFilePath, "*")
  For i = 0 To UBound(TabPieceJointe)
     If (Trim(TabPieceJointe(i)) <> vbNullString) Then
        If (TabPieceJointe(i) <> vbNullString) Then
           mail.Attachments.Add(New Attachment(TabPieceJointe(i)))
        End If
     End If
  Next

  Try
     smtpServer.Send(mail)

     If (sFilePath <> vbNullString) Then
        mail.Attachments.Dispose()
     End If
     mail = Nothing
     smtpServer = Nothing

     Return "Ok"
  Catch ex As SmtpException
     Return "Not ok"
  End Try

End Function

Developer technologies VB
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2022-02-11T02:12:51.353+00:00

    Hi @Stéphane Borel ,
    Please check the following article.
    Maybe you need to re-enable a protocol which has been disabled for Basic Auth.
    Basic Authentication and Exchange Online – September 2021 Update
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Stéphane Borel 6 Reputation points
    2022-02-14T14:32:07.93+00:00

    Hello again,

    I have change my project setting to framework 4.6.1 and everything is fine now

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.