email Posts

Weird Error on Java Mail, “javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client”

I run into a weird error that never happened before, somehow it happened since my user upgrade their Microsoft Mail Exchange’s version. Here is the complete stacktrace,

Caused by: javax.mail.AuthenticationFailedException: 
No authentication mechansims supported by both server and client
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:760)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
    at javax.mail.Service.connect(Service.java:317)

I guess there are several reasons why it happens. First of all, it happens because im using starttls = “true” despite im connecting to port 25, first i change it into “false”. And the other thing is that im using username and password for connecting to my email exchange server, so the workaround is quite easy, just setting my mail.smtp.auth parameter into “false” instead of “true”. Or try sending email without setting username and password.

But actually, it’s much easier to fix the error on the mail server’s side, because it’s only a simple checklist configuration 😛

Weird Error when Connecting Spring’s JavaMailSender to Postfix

I had a weird error today when trying to connect to my server’s postfix mail server. It’s weird because i never had this kind of error when connecting to Google Mail server. This is the error that i see on postfix’s log.

Mar 26 01:50:19 localhost postfix/smtpd[24907]: connect from localhost[127.0.0.1]
Mar 26 01:50:19 localhost postfix/smtpd[24907]: setting up TLS connection from localhost[127.0.0.1]
Mar 26 01:50:19 localhost postfix/smtpd[24907]: SSL_accept error from localhost[127.0.0.1]: 0
Mar 26 01:50:19 localhost postfix/smtpd[24907]: warning: TLS library problem: 24907:error:14094416:SSL routines:SSL3_READ_BYTES:sslv3 alert certificate unknown:s3_pkt.c:1193:SSL alert number 46:
Mar 26 01:50:19 localhost postfix/smtpd[24907]: lost connection after STARTTLS from localhost[127.0.0.1]
Mar 26 01:50:19 localhost postfix/smtpd[24907]: disconnect from localhost[127.0.0.1]

This is my email configuration on Spring’s applicationContext.xml.

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
	<property name="host" value="localhost"/>
	<property name="port" value="25"/>
	<property name="username" value="admin@whatever.com"></property>
	<property name="password" value="password"></property>
	<property name="javaMailProperties">
		<props>
			<prop key="mail.smtp.auth">true</prop>
			<prop key="mail.smtp.starttls.enable">true</prop>
		</props>
	</property>
</bean>

After googling for a while, i found out that somehow the error happen because of TLS problem. The workaround is actually easy, i disabled the starttls property on bean mailSender.

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
	<property name="host" value="localhost"/>
	<property name="port" value="25"/>
	<property name="username" value="admin@whatever.com"></property>
	<property name="password" value="password"></property>
	<property name="javaMailProperties">
		<props>
			<prop key="mail.smtp.auth">true</prop>
			<prop key="mail.smtp.starttls.enable">false</prop>
		</props>
	</property>
</bean>