0

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.

Deepu
  • 2,590
  • 19
  • 52
  • 74
  • 2
    What email client are those people using? Perhaps it really *doesn't* support HTML mail... – Jon Skeet Jul 31 '12 at 06:35
  • also what virus protection are they using, some such as avast cause this problem http://forum.avast.com/index.php?topic=54349.0 – Sean F Jul 31 '12 at 06:38
  • 1
    Might be the email client configuration that prefers text over html. Is it mandatory to send an html email, or can you provide an alternate and valid txt message? – Stéphane Blond Jul 31 '12 at 06:40
  • also, i'm pretty sure you are not using commons-logging for sending the mail, it should be commons-email :) – epoch Jul 31 '12 at 06:40

2 Answers2

2

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.

Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135
  • Thanks Mikko for your quick reply. I have used Commons Email, but I dont know how to use Commons Logging to send e-mails – Deepu Jul 31 '12 at 06:57
1

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.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • A more helpful and informative message would perhaps be "Your email client is configured to not display HTML, but we are too daft to supply a plain-text version, so you will need to yield to our preference instead of yours." – tripleee Jul 31 '12 at 07:03
  • @triplee - Certainly more honest :-) – Stephen C Jul 31 '12 at 07:10
  • Hi Stephen thanks for reply. 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. – Deepu Jul 31 '12 at 07:19
  • A common workaround is to use a message like "If you cannot view HTML, read this message online at `http://unwieldy.links.example.com/ugliness?ghastly-unique-base64-garbage=eW8gbW9tbWEgcGlja3MgeW91ciBjbG90aGVzIGFuZCB5b3UgbmVlZCBhIG1vdXNlIHRvIGRlbGV0ZSBmaWxlcwo`" – tripleee Jul 31 '12 at 07:23