简体   繁体   中英

Apache Commons Email in Jboss send bad html email

Given the following snippet of code:

public static void main(String[] args) throws Exception {
    final Email email = new SimpleEmail();
    email.setHostName("smtp.gmail.com");
    email.addTo("me@gmail.com", "Manuel");
    email.setFrom("me@gmail.com");
    email.setSubject("daje mpo");
    email.setContent("<html><body>22dlkjalskdj <strong>strong</strong><em>em</em><br>aslkdjsal</body></html>", "text/html");
    email.setAuthentication("me@gmail.com", "mypassword");
    email.setDebug(true);
    email.setSSL(true);
    email.setTLS(true);
    String s = email.send();

    System.out.println();
    System.out.println(s);
}

When I execute this piece of code in Eclipse, I receive an email like:

正确的电子邮件

That is what I want!

But then, I tried to use this main inside my application deployed in Jboss-4.0.5, I receive an email like this:

错误的电子邮件

So not only the message isn't an html message, but also the subject of the email was lost, and it seems that instead of send the email with the to receiver it uses a bcc .
I don't have any idea of what can be the cause of this behavior, can someone help me, or just give me some hint.

UPDATE

I notice that when I execute that code "inside" JBoss it doesn't send any headers of the mail message, while executing the same code "inside" Eclipse send the correct message...
I tried to remove all the mail jars in JBoss but it still act this way...

I think you should use

HtmlEmail email = new HtmlEmail();
...

no matter what you're actual problem is.

Sending HTML formatted email

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM