javamail , javax.mail.MessagingException: 501 5.5.1 HELO/EHLO requires domain address

javax.mail.MessagingException: 501 5.5.1 HELO/EHLO requires domain address


Tag: javamail

My web app (java/spring) application in localhost sends email successfully but when i deploy it on host i got following error:

javax.mail.MessagingException: 501 5.5.1 HELO/EHLO requires domain address

I use java mail library.

web server: tomcat 7



after a lot of googling i found the workaround below:

we should add the following props when creating the session to bypass "send hello first" error:

props.put("mail.smtp.auth", "true")
props.put("mail.smtp.transport.protocol", "smtp"); 
props.put("mail.smtp.starttls.enable", "true"); 
props.put("mail.smtp.localhost", "");

but it is a workaround and the root cause is not found.


error: package javax.mail does not exist

I want to run a java program to send emails but I am getting the following errors: error: package javax.mail does not exist import javax.mail.Authenticator; ^ error: package javax.mail does not exist import javax.mail.PasswordAuthentication; ^ error: package javax.mail does not exist import javax.mail.Session; ^ I downloaded the...

How can I fetch emails on Android?

I'm trying to develop an app that fetches emails from a POP3 server that is not Google and I'm facing many problems. I'm using JavaMail library and following TutorialsPoint tutorial. Their example for pop3 works fine on Eclipse/desktop but when I move the code on Android it never works and...

How can I combine multiple IMAP fetch commands?

I'm using JavaMail to fetch data of messages from an IMAP account. For example, I use the following command to retrieve the bodies of the messages with uid 1 to 4: UID FETCH 1:4 BODY[] Is there a way to fetch specific body parts for specific messages? For example, I...

Unable to send email with JavaMail android APi

I have been trying to send an email from android using JavaMail Api for Android. I enabled lesssecure option too. So far I have done following.. package com.emazdoor.encymail; public class Mail extends javax.mail.Authenticator { private String _user; private String _pass; private String[] _to; private String _from; private String _port; private...

JavaMail - Header order

I'm facing some problems because my mail header is out of order. Is possible to keep order that i've added itens? I would like that all my custom header information are before header "Return-Path". I have read about the method addHeader(key, value) and something like a reverse but i don't...

Sending Email in Google Glass

I'm trying to send a email to a (at this moment) hardcoded email adress when a streaming link is generated. I tried using the piece of code that was accepted as awnser HERE However I'm getting a error saying: No provider for smtp does anyone have a clue on what...

javax.mail.MessagingException: [duplicate]

This question is an exact duplicate of: getting errors even after importing jars for sending email 1 answer package com.mca2b; import java.util.Properties; import javax.mail.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class SampleMail { public static void main(String [] args) throws Exception{ String to = "[email protected]";//change accordingly String from...

How to share the same email session between all instances of the application?

Maybe this question is already answered, but I couldn't find the proper answer. I have a web application based in JSF, and I want to share the same email session between all the instances of the application, yet I haven't found how to do that. My questions are: a) What...

JavaMail delete Content-Length header after send

One of my client use specific mail server to receive any data. To send file, I need use headers like this: ... MIME-Version: 1.0 Content-Type: application/octet-stream; Content-Transfer-Encoding: base64 Content-Disposition: attachment; Content-Length: 9245 --- base64 file content --- ... I use this code to create a message, using JavaMail(v1.4.7)...

SMTP Exception handling

I'm developing a code to send mail in Liferay... The probleme here is that I want to send an error message portletRequest.setAttribute("mailError", new String("smobile.error.mail")) when the mail Server ( SMTP) is down.. Here is the source code. try { MailMessage mailMessage = new MailMessage(); mailMessage.setFrom(new InternetAddress(fromEmail)); mailMessage.setSubject(subjectTemplate); mailMessage.setBody(bodyTemplate); mailMessage.setHTMLFormat(true); mailMessage.setTo(new...

Mail doesn't get sent out using Apache Commons Mail

I'm using version 1.3.3 Apache Commons Mail for sending out emails. I've tried changing the Apache mail version using telnet 587 to test for connectivity (it works, so its not about the firewall) trying out with different ports setting SSL/ TSL and tried other bunch of methods configured my...

send mail in android via java mail AuthenticationFailedException

i want to send email in android in my app by javamail and i get AuthenticationFailedException can anyone help me i use this link for sen mail Sending Email in Android using JavaMail API without using the default/built-in app

Javamail search unread mails with a keyword (multiple searchterms)

I know how to search messages with keyword, I also know how to search unread messages. But I don't know how to combine those two things. Here is my code: Properties props = System.getProperties(); props.setProperty("", "imaps"); try { Session session = Session.getDefaultInstance(props, null); //GMail connecting Store store = session.getStore("imaps"); store.connect("",...

Java : Using Javamail to read email

I've been working on a program, that's suppose to use javamail, to read through an inbox, and if an email contains a specific String, it should be opened. First off, this is my first time trying to use this javamail api - I'm pretty sure that my properties are all...

Javamail synchronization when opening mailbox, reading existing and starting MessageCountListener

It seems to me there is no bullet-proof way to open an IMAP mailbox with Javamail, read the existing unread messages and add a MessageChangedListener event listener to read subsequent new arrivals. The app I am writing must process each message once only, and should never miss any emails. This...

Not able to read content of mail using JavaMail

I'm trying to read the content of mail using JavaMail Object msg = message.getContent(); Multipart mp = (Multipart) msg; for(int k = 0; k < mp.getCount(); k++) { BodyPart bp = mp.getBodyPart(k); if (bp.isMimeType("text/plain")) { String s = (String) bp.getContent(); System.out.println("Content:" + s); } else if(bp.isMimeType("text/html")) { String s =...

How to send mail with multiple attachments in java

I have here can send mail with multiple attachment: Properties props = System.getProperties(); String host = ""; props.put("mail.smtp.starttls.enable", "true"); props.put("", host); props.put("mail.smtp.user", from); props.put("mail.smtp.password", pass); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props); MimeMessage message = new MimeMessage(session); Multipart multipart = new MimeMultipart(); // creates body part for the message...

JavaMail IMAP concept that related to download data and memory size

I am now using android javamail to implement sync IMAP messages. I have memory and performance concerned. So i would like to get more clear concept for this when using the java mail api. When getting the inbox folder from the store, I cast it to IMAP Folder. I don't...

Calling second method from first method changes behaviour of first method

I am trying to send an email to two different mail servers. I have a method that points to one mail server send and another method that points to a different mail server sendSecond. I want the email to go to both email servers, but by calling the second mail...

Javamail ClassCastException when sending multipart messages

I am getting the following exception when attempting to send a multipart message: java.lang.ClassCastException: cannot be cast to javax.activation.DataContentHandler at javax.activation.MailcapCommandMap.getDataContentHandler( at javax.activation.MailcapCommandMap.createDataContentHandler( at javax.activation.DataHandler.getDataContentHandler( at...

Extract MIME encoded content from email using JavaMail

I have an email message that has contentType: TEXT/PLAIN; charset="=?utf-8?B?ICJVVEYtOCI=?=" What do I need to extractContent to eliminate the =?utf-8?B?ICJVVEYtOCI=?= I have tried the following: import; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.internet.MimeMultipart; public class ExtractContentText { private static String extractContent(MimeMultipart mimeMultipartContent) throws MessagingException { String...

Not able to view 'To' field using java mail API

I am trying to fetch/read my email using java mail API. I am using following line to read the 'To' field System.out.println("TO:" + message.getRecipients(Message.RecipientType.TO)); And it is giving the following output : TO:[Ljavax.mail.internet.InternetAddress;@6e1567f1 where as I want the output like [email protected] ...

java mail Base64 encoded string to image attachment

I have a base64 encoded string which is posted using JSON into a Spring form. data:image/png;base64,iVBORw0KGg......etc I want to add this image as an attachment to an email. Attaching the file works fine, but it is just adding the base64 string as the attachment. I am using the following code...

Caused by: unable to find valid certification path to requested target

A spring mvc app uses JavaMail to connect to dovecot/postfix. Both the spring mvc app and the dovecot/postfix installation are running on the same CentOS 7 physical server box. The app was able to use JavaMail to successfully make an imap connection until just recently, when some scripts for setting...

error while fetching pop3 mail

I got the following error while fetching mail via pop3: (the first 4 row are a prints of the email content) 15/06/2015 16:56:42 RunJava JVM: dcwTXKwiJYV2+XMArhAA+CmQT7elRfEfVfGumfETQdM0jX0eDUZTLDaTQBIowOCrsvzSLwT1HtWb 15/06/2015 16:56:42 RunJava JVM: 4o8SaM3x48NXI1SzNra2T2884mUpHKVnGxj0Byyj8an+Kus6OnxV8GGbULMLYu/2ovMFFuSQV3n+ 15/06/2015 16:56:42 RunJava JVM: E98HHbOAc0ATa5e+MfAPjTw0174km1nT9buRbXEEkSxIjkhfkHO0DeGGMfdwTzXafEzxHrcniLRP 15/06/2015 16:56:42 RunJava JVM:...

Can't send mail via javamail-android

I read guides for javamail-android and some posts on stackoverflow. E.g. How do you send mail in Android using JavaMail API? I get message "Mail send successfully...". But mail does not comes to reciever addresses. And I have following output: 02-11 09:53:38.988 2674-2674/com.example.mailapp W/System.err﹕ android.os.NetworkOnMainThreadException 02-11 09:53:38.988 2674-2674/com.example.mailapp W/System.err﹕ at...

javamail-1.4.5 error at parsing gmail message received via imap

I'm using javamail-1.4.5 for getting messages from gmail (imap). If Content-Disposition has an unquoted parameters, method getDisposition fails. message part: Content-Transfer-Encoding: 7bit Content-Type: message/rfc822 Content-Disposition: attachment; creation-date=Wed, 11 Feb 2015 10:23:48 GMT; modification-date=Wed, 11 Feb 2015 10:23:48 GMT exception: javax.mail.internet.ParseException: Expected ';', got "," at javax.mail.internet.ParameterList.<init>( at...

javax.mail.internet.ParseException: In Content-Type string , expected '/', got :

I want to implement mail with attached file using JSF. I tried this code: private Part file; private String sendFromGMail(String from, String pass, String[] to, String subject, String body) { String status; Properties props = System.getProperties(); String host = ""; props.put("mail.smtp.starttls.enable", "true"); props.put("", host); props.put("mail.smtp.user", from); props.put("mail.smtp.password", pass); props.put("mail.smtp.port", "587");...

How to use SpringTemplateEngine when using Spring Boot

I am using Thymeleaf SpringTemplateEngine to create a HTML e-mail on my Spring application. When I was using pure Spring MVC everything was perfect. Now with Spring Boot the class can't find my .html template. I think the problem is with ServletContext that is not returning the right path, but...

Can use webmail but cannot send via javax.mail

I currently have a mail server up and running. I can log into my web-mail client via Web-mail allows me to send and receive email appropriately. Logs show all the mail come in and out and it's fine. I've sent from here to my gmail account and back. However,...

How to read mail and insert into database using Mule?

I have to create an application in Mule which will read the mail from a store and save it's details in a database. I know how to insert the data into the database but I am unable to find any solution about the mail. How do I read the mail...

Set “mail.strictly_mime.parm_folding” in javamail

I'do use javamail to send mail with long filename attachments. The javamail acts accordingly to more recent RFC, and span the filename in two lines of the mail's header, like this example: ------=_Part_0_978693914.1433356404377 Content-Disposition: ATTACHMENT; filename*0="=?UTF-8?Q?arquivo_com_nome_grande_e_acentua=C3=A7=C3=A3o.png\"; f"; filename*1="ilename*1=\"?=" Content-Type: APPLICATION/OCTET-STREAM; name*0="=?UTF-8?Q?arquivo_com_nome_grande_e_acentua=C3=A7=C3=A3o.png\"; n"; name*1="ame*1=\"?=" Content-Transfer-Encoding: BASE64 Mail...

Issue reading email body when email has attachments?

I found a nice code to read email from my inbox email server, the code works just fine, but have a couple issues: I need to capture the message body of each email, but when the email has some attachment, i receive a string like this [email protected], or [email protected], instead...

No login methods supported! JavaMail, Dovecot, CentOS 7

A spring mvc app running on a CentOS 7 server has been successfully making IMAP connections to the Maildir inbox managed by dovecot on the same CentOS 7 physical server box. However, the app is no longer able to make an IMAP connection after some scripts from this OpenVPN tutorial...

Images are converted to .bin files in java-mail

I am trying to send a mail which has html contents[Includes Images] using javamail API , when ever I try to send the mail through unit test , its working as excepted meaning html contents are getting delivered properly but when I use the same code in application [When running...

Access denied to default session when i try to send mail automatically using scheduler

I have a requirement of sending the Email automatically from and to my corporate Email account in specific Intervals of time. But I get Access Denied to default session Exception even though I am not using default instance. Authentication is not required. Please help me solve this exception and send...

java mail api (1.5.3) not working in recent jre1.8.25

im using javamail to send mail in an application. every thing works fine. but when i change the Runtime to jre1.8.25, i got exception as nested exception is: RSA premaster secret error at com.sun.mail.smtp.SMTPTransport.openServer( at com.sun.mail.smtp.SMTPTransport.protocolConnect( at javax.mail.Service.connect( at MainClass.main( Caused by: RSA premaster secret error at...

Send a table inside of RTF message JavaMail

I'm trying to send a email with a Table in string with RTF, but when I check the email the message body, the table lost the format, so I wondering what I'm doing wrong, this is the following chunk of code to send and email public static void send(String asunto,...

Read Recent and Unseen message using javax.mail

I am using javax.mail to read messages from inbox folder using 'imaps' protocol. I am using the below code snippet: Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect(); store.getFolder("inbox");; FlagTerm unseenFlagTerm = new FlagTerm(new Flags(Flags.Flag.SEEN), false); FlagTerm recentFlagTerm = new FlagTerm(new Flags(Flags.Flag.RECENT), true); But I am not...

how to open mail in draft and attach file to mail using java

I was trying to send a file using mail but I wanted to first it open in a draft mail like mailto in jsp. I had implemented mail to functionality in Java but I am not able to attach file to opened mail. other are working file except the attachment....

JavaMail MimeMessage.getContent unsupported encoding

I´m having a problem with parsing some type of mail encoding with charset=t.101-g2 I´m using JavaMail in Grails directly using the lib, getting the unread emails from IMAP, and for each message try to get the content with Object msgContent = msg.getContent() And that line is throwing the error. The...

Why my javamail program not running through jdeveloper?

I am working on Oracle MAF app and using Java mail API for sending outlook meeting requests. I can successfully send mail from java command-line, but when trying same using Mobile app, the code doesn't go after where creating "MimeMessage" class object. MimeMessage message = new MimeMessage(mailSession); printStackTrace() shows this...

Reading email from gmail is not working

I am using Java Mail API along with the following code to read email from my gmail account. import java.util.Properties; import javax.mail.Folder; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.NoSuchProviderException; import javax.mail.Session; import javax.mail.Store; public class CheckMails { public static void check(String host, String storeType, String user, String password) { try {...

JavaMail reading recent unread mails using IMAP

I have a requirement to retrieve unread mails from Gmail. I am using Java Mail API. By default, this API retrieves mails from the oldest to newest. But I need to retrieve recent mails first. Is it possible? Thanks in advance.

java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream

I'm trying to send an email through Java Mail API and it works fine on my laptop. When I'm doing exactly the same in Heroku, I'm getting this: java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream.(Ljava/io/InputStream;Lcom/sun/mail/util/MailLogger;)V at com.sun.mail.smtp.SMTPTransport.initStreams( at com.sun.mail.smtp.SMTPTransport.openServer( at com.sun.mail.smtp.SMTPTransport.protocolConnect( at javax.mail.Service.connect( at ... Here...

How does JavaMail API expunge messages when IMAP folder is closed

I wonder, how JavaMail API expunges IMAP messages when Folder.close(true) is being called? According to the docs, the only parameter "expunge" of method "close" determines whether to expunge all messages that have been previously marked with a \Deleted flag. In the source code (V. 1.4.7), however, I cannot see any...

How to make dependency transitive in Gradle

I have downloaded javax.mail-api-1.5.3.jar file copied into app/libs folder and then right click , add as library. Then following line appears under dependency compile files('libs/javax.mail-api-1.5.3.jar') I want to make this dependency transitive.Because I have mention javax.mail-api library dependencies in pom.xml file like follows. <dependencies> <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> <version>1.5.3</version> <scope>test</scope>...

Send emails using JavaMail from my own domain in AWS

We have been sending email notifications (outbound only) to our customers using a gmail address [email protected] and we got smtp host and port configured in our server. Now we would like to send these emails with our domain name i.e [email protected] Our site is hosted on AWS and we bought...

Send Mail by MimeMessageHelper sends mail to All CC but in rackspace it shows only one email id in CC

i am sending mail with help of spring in which i want multiple email ids in CC, all receives the mail but problem is when they open the email in rackspace( it shows only one email id in CC but actually there is multiple email ids and when i open...

SMTP JavaMail : Getting SMTPTransport Not Connected error with Threads

I'm trying to work with the JavaMail API. I'm trying to send multiple emails using the same transport object to avoid re-authentication. transport = mailSession.getTransport("smtp"); transport.connect(host, mail.getSenderAddress(), password); for (int i = 1; i <= 10; i++) { transport.sendMessage(mailMessage, mailMessage.getAllRecipients()); } This works fine and I'm able to send 10...