4

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

kishore
  • 127
  • 1
  • 13
  • `smtp.exg6.exghost.com/` (looks unorthodox with a slash). That might be the problem. – dmahapatro Jul 31 '14 at 00:09
  • I removed '/' but that didn't solve the problem. Are all the other values host, port and props are correct ? – kishore Jul 31 '14 at 03:00
  • What happens when you try to telnet to those ports while on the same machine running your Grails app server? Can you connect? Second, have you contacted the Exchange admin to confirm the host, ports, and protocols? Ages ago I administered Exchange and SMTP was not enabled or open by default. – Philip Aug 06 '14 at 03:49

2 Answers2

0

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.

Steve Hole
  • 348
  • 2
  • 12
  • `host = "smtp.exg6.exghost.com" port = 465 username = "xxxx" password = "xxxx" props = ["mail.smtp.auth":"true", "mail.smtp.socketFactory.port":"465", "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory", "mail.smtp.socketFactory.fallback":"false"]`. I was able to connect to MS exchange server via thunderbird only by using exquilla plugin. Could you pls look what's wrong with my config, its driving me crazy. – kishore Aug 04 '14 at 18:08
  • If you are able to connect with another client, then you should just replicate that configuration in the mail plugin. Go in order. (1) Does the host name resolve? (2) Is the port active? (3) Is SSL enabled on the server. ... Try using telnet as suggested above. The gmail setup in the documentation does work -- I'm using it my code. So you have an error somewhere in your setup. You have to be sure that you are connecting to a valid SMTP server first. – Steve Hole Aug 06 '14 at 21:30
  • The underlying implementation of the mail plugin is Spring JavaMail. You should look at the class JavaMailSenderImpl for details on connection logging and see if you can get the protocol failure messages that are occurring. I presume at this point that you are no longer getting connection errors? If you are, then your host/port information is wrong. If you are connecting but cannot log in then your SSL/authentication information is wrong. – Steve Hole Aug 06 '14 at 21:38
0

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.

kishore
  • 127
  • 1
  • 13