ASP JMail 4.5 SMTP Authentication for Office365

3.3k Views Asked by At

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..?

1

There are 1 best solutions below

2
John On

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

Dim objMail, iConfg, Flds
Set objMail = Server.CreateObject("CDO.Message")
Set iConfg = Server.CreateObject("CDO.Configuration")
Set Flds = iConfg.Fields
With Flds

        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
    .Update
End With
        objMail.Configuration = iConfg
        objMail.To = Request.Form("recipient")
        objMail.From = "[email protected]"    
        objMail.Subject = "Email form submission"
        objMail.TextBody = Request.Form("message")
        objMail.Send

Set objMail = Nothing