-->

Grails mail plugin configuration for MS Exchange s

2019-02-19 01:30发布

问题:

I am able to send email using my gmail account from my grails application but when I use MS exchange server account I am getting this error

Message: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.exg6.exghost.com/, 25; timeout -1;

Configuration I used is :

mail {
      host = "smtp.exg6.exghost.com"
      port = 25
      username = "xxxx"
      password = "xxxx"
      props = ["mail.smtp.auth":"true",
               "mail.smtp.socketFactory.port":"25",
               "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
               "mail.smtp.socketFactory.fallback":"false"]

I am not sure what configuration to use. I tried changing port to 465 & 993 but that didn't work too. Please help

回答1:

There are several things wrong with your setup. First of all, you are submitting mail to a Microsoft Exchange server (presumably), not Outlook. Outlook is a mail client and only provides end user functionality by connecting to the same server that you are trying to get the Mail plugin to connect to.

  1. Your host name must be a valid Internet DNS host name -- therefore it must be "smtp.exg6.exghost.com". This might be all you have to do depending on the submission/relay policies in your SMTP server. Most likely you need to read on.

  2. The SMTP protocol supports authentication and security for mail submission (new message injection) using either SSL or SASL. If you are using SSL, the default port to connect to is 465 (SMTPS port). If you are using SASL, then most servers are configured to accept new mail with authentication on port 587 (submit service port). Most SMTP servers will not accept mail submission on port 25.

In your case it looks like you are trying to connect with SSL, so you probably want to configure it using the SMTPS setup. To make sure that you have a proper setup, use a mail client like Thunderbird to try to make an SMTP connection to the server. It actually has a discovery algorithm in it that will try the common setups and report success when it has found one. Once you know what the connection parameters are, then you can proceed with configuring the Mail plugin.



回答2:

I finally got this working. Turns out Microsoft provide a separate API / web-services to send email and perform all other mail related operations. This API gives developers programmatic access to Exchange Online, Exchange Online as part of Office 365, and versions of Exchange starting with Exchange Server 2007 Service Pack 1 (SP1). Click here for details.

exg6.exghost.com is host for Exchange Server 2007

And I am not sure but I think Exchange server 2007 and onwards don't use SMTP.