Pritesh Patel     Feb,08 2017

Getting javax.mail.MessagingException: Could not connect to SMTP host: xxxxxxx, port: 465, response: -1 error in ColdFusion

Well, error indicates that could not connect to SMTP host and this was driving me crazy because I have double-tripple check setting and look everything good and graph of my craziness goes high when I found it does work most of the time and sometime it get fails. Contacted with mail service provider and he confirmed everything OK on his side. 

Since we are using dedicated server we have setup mail parameter at administrator level to avoid providing mail parameters every time in cfmail tag. Mail server is using secure SSL connection and accordingly we have change the port to 465 and check the box "Enable SSL socket connection to mail server". After setting verified connection and it work too. Everything good, sends test email and received it successfully. After sometime I have notice lots of undelivered emails in “Undelivr” folder and as usual respool it to make sure ColdFusion try one more time. Respooling normally work but not for me. 

To investigate further on this open up .cfmail and below content (I have replaced content with dummy text) found.

type:  text/html; charset=UTF-8
	server:  xxxxxxx:465
	server-username:  xx@xxxxx.com
	server-password:  *********
	from:  yyy@xxxxx.com
	to:  zzz@zzz.com
	subject:  SUBJECT LINE TEXT
	X-Mailer:  ColdFusion 9 Application Server
	body:  xxxxxxx
	body:      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
	body:    exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
	body:    pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.


At first glance I found everything ok, also compare with other .cfmail file which successfully send and look identical, my question was why respooling doesn't work? Why does it send back to Undelivr folder although other emails was sending same time? Tried to send email with cfmail tag with all server and credential provided within tag itself.

<cfmail 
	server="xxxxxxx"
	username="xx@xxxxx.com"
	password="*********"
	from="yyy@xxxxx.com"
	to="zzz@zzz.com"
	usessl="true"
	port="465"
	subject="SUBJECT LINE TEXT">
	Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
	</cfmail>

And open .cfmail file generated in "spool" folder and notice two changes, two extra parameter added usessl and port when I have send email with server detail inside CFMAIL tag. 

type:  text/html; charset=UTF-8
	server:  xxxxxxx:465
	server-username:  xx@xxxxx.com
	server-password:  *********
	usessl:  true
	port:  465
	from:  yyy@xxxxx.com
	to:  zzz@zzz.com
	subject:  SUBJECT LINE TEXT
	X-Mailer:  ColdFusion 9 Application Server
	body:  xxxxxxx
	body:      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
	body:    exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
	body:    pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

As a curiosity I just add same two lines in undelivered email and respool it and guess what? it works. Question is, why same parameters doesn't added when I am using administrator settings even though server port was setup 465 and usessl was checked. Is it coldfusion issue? I am not sure, but going to submit bug though.