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


Octocat Save up to a workweek a year by efficiently managing your coding bookmarks, aka #codingmarks, on www.codingmarks.org. Share your favorites with the community and they will be published weekly on Github. Help us build the programming-resources location - Star


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 I save a workweek a year by efficiently managing my codingmarks

Finding a desired link, you already visited, can be a tedious job and sometimes even frustrating. It normally takes 30 seconds or more to look for a link the traditional way, and I do that at least 20 times a day. With codingmarks.org it takes about 10 seconds, so I get a time saving of around 20 * 20 / 60 = 6.66 minutes a day. Over a year's time this translates to around 40+ hours of saved time. Continue reading

New codingmarks published in week 52 of 2018

Published on January 01, 2019