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