Pregunta

I have a weird problem with javamail. When i try to send a mail with a subject beginning with the letter 'n' the mail doesn't get sent. I am connecting to a smtp mailserver.

Session session = Session.getInstance(properties);

    try {
        MimeMessage msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress(sender));
        msg.addRecipients(Message.RecipientType.TO, mail_list_addresses);

        //These work!
        msg.setSubject(MimeUtility.encodeText("Pode Has Fallen Down", "utf-8", "B"));
        msg.setSubject(MimeUtility.encodeText("Fallen Down It Has", "utf-8", "B"));
        msg.setSubject(MimeUtility.encodeText("It Has Fallen Down", "utf-8", "B"));

        //These doesn't work
        msg.setSubject(MimeUtility.encodeText("Node Has Fallen Down", "utf-8", "B"));
        msg.setSubject(MimeUtility.encodeText("node Has Fallen Down", "utf-8", "B"));
        msg.setSubject(MimeUtility.encodeText("N", "utf-8", "B"));



        msg.setText(standard_msg + mqttMessage + standard_msg_end);

        SMTPTransport t = (SMTPTransport) session.getTransport("smtp");

        t.connect();
        t.sendMessage(msg, msg.getAllRecipients());
        t.close();
    } catch (MessagingException mex) {
        mex.printStackTrace();
    }catch (Exception e){
        e.printStackTrace();
    }

These are my SMTP settings

sender = "sender@test.com";
host = "server.adress.com";
properties = System.getProperties();

properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.port", "25");

properties.setProperty("mail.smtp.auth", "false");
properties.put("mail.smtp.ssl.enable", "false");
properties.setProperty("mail.smtp.starttls.enable", "false");

properties.setProperty("mail.debug", "true");  

properties.setProperty("mail.smtp.quitwait", "true");

Any clues why this is?

Or could it simply be that my mailserver doesn't accept subjects starting with the letter 'n'? I have tried different encodings, and just using setSubject("whatever") without any result.

EDIT

The mail got sent but arrived in the spam folder (was hidden so i didn't notice them).

¿Fue útil?

Solución

public class MimeUtility *This is a utility class that provides various MIME related functionality.*

There are a set of methods to encode and decode MIME headers as per RFC 2047. Note that, in general, these methods are not needed when using methods such as setSubject and setRecipients; JavaMail will automatically encode and decode data when using these "higher level" methods.

Im not sure exactly what is going on, but it might be the side effect of some kind of "double encoding". Try removing the unnecessary calls to MimeUtility.encodeText()

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top