Page 1 of 1

[SOLVED] JavaMail not working with Office 365

PostPosted:Fri Feb 01, 2019 7:52 pm
by dferguson
I have successfully used the tomcat mail with gmail before, but this installation requires me to use our Office 365 account.

Here is my server.xml file section for mail configuration.
Code: Select all
<Resource name="mail/OpenKM"
		auth="Container" type="javax.mail.Session"
		mail.transport.protocol="smtp"
		mail.smtp.host="smtp.office365.com"
		mail.smtp.from="Docs@example.net"
		mail.smtp.username="Docs"
		mail.smtp.password="password"
		mail.smtp.port="587"
		mail.smtp.startttls.enable="true"
		mail.debug="true"
		mail.smtp.auth="true"/>
However, I keep getting this when trying to check the email function from the admin panel.

Code: Select all
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication

Re: JavaMail not working with Office 365

PostPosted:Fri Feb 01, 2019 8:50 pm
by dferguson
I cleaned up my config settings to:
Code: Select all
<Resource name="mail/OpenKM"
		type="javax.mail.Session"
		mail.transport.protocol="smtp"
		mail.smtp.auth="true"
		mail.smtp.host="smtp.office365.com"
		mail.smtp.user="Docs"
		password="password"
		mail.smtp.port="587"
		mail.smtp.starttls.enable="true"
		mail.debug="true"
		/>
and now I get this...
Code: Select all
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.office365.com", port 587, isSSL false
220 BN7PR02CA0012.outlook.office365.com Microsoft ESMTP MAIL Service ready at Fri, 1 Feb 2019 20:35:45 +0000
DEBUG SMTP: connected to host "smtp.office365.com", port: 587

EHLO dferguson-virtual-machine
250-BN7PR02CA0012.outlook.office365.com Hello [47.44.209.114]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 SMTP server ready
EHLO dferguson-virtual-machine
250-BN7PR02CA0012.outlook.office365.com Hello [47.44.209.114]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH LOGIN XOAUTH2
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN XOAUTH2"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed

Re: JavaMail not working with Office 365

PostPosted:Sat Feb 02, 2019 7:16 pm
by jllort
Seems is working.

Re: JavaMail not working with Office 365

PostPosted:Mon Feb 04, 2019 12:50 pm
by dferguson
Code: Select all
DEBUG SMTP: AUTH LOGIN failed
credentials are correct but I still get this...

Re: JavaMail not working with Office 365

PostPosted:Thu Feb 07, 2019 7:07 pm
by jllort
I have updated the documentation section with a configuration what sure it is working https://docs.openkm.com/kcenter/view/ok ... -mail.html

Re: JavaMail not working with Office 365

PostPosted:Thu Feb 07, 2019 8:32 pm
by dferguson
Great!

You might clarify that as indicated by the Office 365 Javadocs link provided in the OpenKM documentation, the username would be:
Code: Select all
mail.smtp.user="example@yourdomain.com"
mail.smtp.from="example@yourdomain.com"