Question

I am sending email using apache-commons-logging.jar. I am able to send html email successfully, but few people are getting Your email client does not support HTML messages message in their mail. The following is the code sample -

HtmlEmail htmlEmail = new HtmlEmail();
htmlEmail.setHostName("localhost");
htmlEmail.addTo(email, "demo1@sample.com");
htmlEmail.setFrom("demo2@sample.com", "Demo2");
htmlEmail.setSubject("Subject Line");

String msg = "<html>Hi Demo1,";
msg       += "<br><br> &nbsp;&nbsp;&nbsp;&nbsp; A very warm Welcome";
msg       += "</html>";
htmlEmail.setHtmlMsg(msg);

// set the alternative message
htmlEmail.setTextMsg("Your email client does not support HTML messages");

// send the email
htmlEmail.send();

I am not understanding how to resolve this problem.

Please Gurus help me.

Thanks in advance.

Was it helpful?

Solution

Likely you are using Commons Email and not Commons Logging to send e-mails.

It is expected that those who configured their e-mail client to prefer text, actually do see the text instead of HTML. Only thing what you as a sender can do is to write more meaningful plain text message.

OTHER TIPS

The solution to this "problem" is to change:

htmlEmail.setTextMsg("Your email client does not support HTML messages");

to

htmlEmail.setTextMsg("A very warm Welcome");

... or leave it out altogether. It is the user's choice as to whether they configure their email client to display the HTML or plain text version of the email body. Ideally you should send both, but if you are only going to send one version, then you should simply leave the other one out.


I just given example of "A Very warm Welcome", there are many html mesgs like Hyperlink. So I cant give these messages in Plain Text format.

I suggest that you read this advice:

(I know it is primarily addressed to email marketeers ... but most of the advice applies equally to software generated emails as well.)

The bottom line is that if you want your emails to be readable by your users, it is your job to make sure that there are viable HTML and plain text versions. If you don't, you risk alienating some of your users who can't or won't read HTML email for various reasons.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top