简体   繁体   English

Jboss中的Apache Commons电子邮件发送错误的html电子邮件

[英]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: 当我在Eclipse中执行这段代码时,会收到类似以下的电子邮件:

正确的电子邮件

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: 但是,然后,我尝试在部署于Jboss-4.0.5的应用程序中使用此main ,我收到如下电子邮件:

错误的电子邮件

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 . 因此,不仅该消息不是html消息,而且电子邮件的主题也丢失了,并且似乎使用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... 我注意到,当我在“内部” JBoss中执行该代码时,它不会发送邮件消息的任何标头,而在“内部” Eclipse中执行相同的代码时,它将发送正确的消息...
I tried to remove all the mail jars in JBoss but it still act this way... 我试图删除JBoss中的所有邮件罐,但它仍然以此方式运行...

I think you should use 我认为你应该使用

HtmlEmail email = new HtmlEmail();
...

no matter what you're actual problem is. 不管你是什么实际问题。

Sending HTML formatted email 发送HTML格式的电子邮件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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