1

I use Apache Commons Mail and recognised that the email subject (and other settings like character encoding) are not used at all:

    props.put("mail.smtp.host", "localhost");
    Session s = Session.getInstance(props, null);
    s.setDebug(true);

    MimeMessage message = new MimeMessage(s);
    message.setHeader("Content-Type", "text/plain; charset=UTF-8");
    message.addHeader("Content-Transfer-Encoding", "quoted-printable");
    message.setFrom(new InternetAddress("me@home.com"));
    message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("you@abroad.com"));
    String subj = MimeUtility.encodeText("");
    message.setSubject("my subject with specials äöü");

    message.setText("Some text with special äöü");
    Transport.send(message);

The debbugging output shows:

 DEBUG SMTP: useEhlo true, useAuth false
 DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
 220 mydomain ESMTP Postfix
 DEBUG SMTP: connected to host "localhost", port: 25

 EHLO MyComputer
 250-PIPELINING
 250-SIZE 10485760
 250-VRFY
 250-ETRN
 250-ENHANCEDSTATUSCODES
 250-8BITMIME
 250 DSN
 DEBUG SMTP: Found extension "PIPELINING", arg ""
 DEBUG SMTP: Found extension "SIZE", arg "10485760"
 DEBUG SMTP: Found extension "VRFY", arg ""
 DEBUG SMTP: Found extension "ETRN", arg ""
 DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
 DEBUG SMTP: Found extension "8BITMIME", arg ""
 DEBUG SMTP: Found extension "DSN", arg ""
 DEBUG SMTP: use8bit false
 MAIL FROM:<me@home.com>
 250 2.1.0 Ok
 RCPT TO:<you@abroad.com>
 250 2.1.5 Ok
 DEBUG SMTP: Verified Addresses
 DEBUG SMTP:   you@abroad.com
 DATA
 354 End data with <CR><LF>.<CR><LF>

 Some text with specials =C3=A4=C3=B6=C3=BC
 .
 250 2.0.0 Ok: queued as 9F623345F99
 QUIT
 221 2.0.0 Bye

As far as I understand the SUBJECT should be set in the DATA section of the SMTP message.

How can I fix this?

centic
  • 15,565
  • 9
  • 68
  • 125
Klaus
  • 11
  • 2

2 Answers2

1

If you take a look at this (sorry for a cached link, but Oracle seems to have this link (re)moved or something):

it seems that Apache Commons somehow influences Java Mail. The example you provided seems to be a standard Java Mail way of sending mails. So, can you try to either:

icyrock.com
  • 27,952
  • 4
  • 66
  • 85
  • After setting the subject the debugger shows that subject, content-type and content-transfer-encoding are set properly. – Klaus Nov 18 '10 at 12:37
  • However, after setting the text the content-type and content-transfer-encoding settings are gone. – Klaus Nov 18 '10 at 12:37
  • @Klaus What do you see when you print `email.getSubject()` just before `email.send()` in the last example I mentioned (http://commons.apache.org/email/userguide.html)? Is it properly set then or not? – icyrock.com Nov 18 '10 at 14:43
  • So are you saying that when you execute this example all the way and you receive the message on your server, it doesn't have the subject? – icyrock.com Nov 18 '10 at 15:33
  • Are you using the example verbatim from the site (except, of course, changing the host:port and authentication) or did you change anything? What exactly are the two lines where you set the subject and the message itself? It's strange that you get the message OK otherwise, but not the subject. – icyrock.com Nov 18 '10 at 15:52
  • Ok. Now I can reveal the whole story: in complete isolation this works now. However, I am using it in a more complex setting with Springs' org.springframework.mail.javamail.JavaMailSenderImpl implementation. – Klaus Nov 18 '10 at 17:05
  • Then you should use Spring's email support, as described here: http://static.springsource.org/spring/docs/2.0.x/reference/mail.html. Also look at this tutorial: http://wheelersoftware.com/articles/spring-javamail.html. I suggest you to try to stick to the examples they give in the docs/tutorials, as any changes you make might make it not work - first make it work on a basic level, then change step by step to meet your requirements. Otherwise, you will run into problems that are hard to debug, as you could see. – icyrock.com Nov 18 '10 at 17:11
0

I have the same problem.

I remove library

<artifactId>geronimo-javamail_1.4_spec</artifactId>
<groupId>org.apache.geronimo.specs</groupId>

from my project.

It's work for me!

Furetto
  • 329
  • 3
  • 9