Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

SMTPSendFailedException "Invalid HELO name" - Spring Batch with Spring Boot

DZone's Guide to

SMTPSendFailedException "Invalid HELO name" - Spring Batch with Spring Boot

· Java Zone ·
Free Resource

Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.

If you find yourself getting the following error, 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.

Connect any Java based application to your SaaS data.  Over 100+ Java-based data source connectors.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}