We have some old apps written in Classic ASP which send mail using JMail (w3JMail v 4.5). We are in the process of moving from a local Microsoft Exchange server to Office 365. We need these old apps to continue to work, using JMail to send e-mail.
Our current ASP code (which references the Exchange server by IP):
Set objMail = Server.CreateObject("JMail.Message")
objMail.MailServerUserName = "domain\username"
objMail.MailServerPassWord = "password"
objMail.ContentType = "text/plain"
objMail.From = "[email protected]"
objMail.AddRecipient "[email protected]"
objMail.Subject = "Test"
objMail.Body = "Test"
objMail.Send("10.10.10.1")
Set objMail = Nothing
This is the new version I have to try and use our Office 365 account:
Set objMail = Server.CreateObject("JMail.Message")
objMail.Silent = True
objMail.Logging = True
objMail.MailServerUserName = "[email protected]"
objMail.MailServerPassword = "password"
objMail.ContentType = "text/plain"
objMail.From = "[email protected]"
objMail.AddRecipient "[email protected]"
objMail.Subject = "Test"
objMail.Body = "Test"
If objMail.Send("smtp.office365.com:587") Then
Response.Write "Sent an e-mail..."
Else
Response.Write( "ErrorCode: " & objMail.ErrorCode & "<br />" )
Response.Write( "ErrorMessage: " & objMail.ErrorMessage & "<br />" )
Response.Write( "ErrorSource: " & objMail.ErrorSource & "<br /><br />" )
Response.Write( "" & objMail.Log & "<br /><br />" )
End If
Set objMail = Nothing
I know that our username and password are correct, and that the host name is correct.
This is taken from the log output:
AUTH LOGIN
<- 504 5.7.4 Unrecognized authentication type
Authentication failed.
smtp.office365.com:587 failed..
No socket for server. ConnectToServer()
How can we set the authentication type using JMail..?
Try Changing the port from 587 to 25. The Office365 smtp server seems to prefer this
(NB I don't know if this applies to Jmail but it does apply to CDO and most third party mail components in Classic ASP seem to be wrappers for CDO.)
Edit - CDO example, tried and tested with smtp.office365.com