SMTPSendFailedException “Invalid HELO name” – Spring Batch with Spring Boot

If you find yourself getting the following errror, when trying to send an email in Java:

com.sun.mail.smtp.SMTPSendFailedException: 550 Access denied – Invalid HELO name (See RFC2821 4.1.1.1)

Failed message 1: com.sun.mail.smtp.SMTPSendFailedException: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

	at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:448)
	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:346)
	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:363)
	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:351)
	at org.podcastpedia.batch.jobs.addpodcast.service.EmailNotificationServiceImpl.sendPodcastAdditionConfirmation(EmailNotificationServiceImpl.java:53)
	at org.podcastpedia.batch.jobs.addpodcast.SuggestedPodcastItemWriter.write(SuggestedPodcastItemWriter.java:50)
	at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175)
	at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
	at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor$3.doWithRetry(FaultTolerantChunkProcessor.java:329)
	at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:263)
	... 43 more

and cannot figure out why does it not work?!, EVEN THOUGH you can send emails via Telnet using the same configuration as the one set up for the Java client or you set the mail.smtp.localhost property to the  fully qualified domain name (FQDN) of the client host – that might be IP address of the client host –  as suggested in the JavaMail API FAQ… THEN it might be that you are using an old version of the java mail api.

Solution

I have configured a Spring Batch job with Spring Boot version 1.1.3.RELEASE by building on the Getting started guide for Spring Batch on Spring.io, and for some reason the spring-boot-starter-remote-shell artifact comes with the java mail library in version 1.4. Replacing this with the version 1.4.7 (version which works for the batch jobs developed in my own kind of way…) solved the problem for me:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.podcastpedia.batch</groupId>
    <artifactId>gs-batch-processing</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.3.RELEASE</version>
    </parent>

    <dependencies>
	........
 		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-remote-shell</artifactId>
		    <exclusions>
		        <exclusion>
					<groupId>javax.mail</groupId>
					<artifactId>mail</artifactId>
		        </exclusion>
		    </exclusions>				
		</dependency>
		<dependency>
			<groupId>javax.mail</groupId>
			<artifactId>mail</artifactId>
			<version>1.4.7</version>
		</dependency>
	........
    </dependencies>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
            <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

Conclusion

If you get this error in any circumstances make sure you use a newer version of the java mail api. Version 1.4.7 worked for me.

P.S. A complete Spring Batch tutorial with Spring Boot will follow soon, so stay tuned…

 

Podcastpedia image

Adrian Matei

Creator of Podcastpedia.org and Codingpedia.org, computer science engineer, husband, father, curious and passionate about science, computers, software, education, economics, social equity, philosophy - but these are just outside labels and not that important, deep inside we are all just consciousness, right?

How to configure Nginx in production to serve an Angular app and reverse proxy NodeJS

Install Nginx on Ubuntu Server, understand configuration files, configure SSL, serve static files, reverse proxy Keycloak and NodeJS servers Continue reading