javax.mail not including Sender Name in emails

No matter what I try, I can't get the Sender Name to show up in the outgoing mails sent through the javax.mail Session class.

Please note that I'm using Rhino so there's a mixture of javascript and java here, but the code problem exists in pure java as well.

var _java = JavaImporter(javax.mail, javax.mail.internet, java.util);

        var props = new _java.Properties();
        props.put("mail.smtp.host", myHost);
        props.put("mail.smtp.port", "465");
        props.put("mail.smtp.user", myUserName);
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.socketFactory.port", 465);
        props.put("mail.smtp.socketFactory.class",
                  "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.socketFactory.fallback", "false");
        props.put("mail.smtp.ssl", "true");

        var session = _java.Session.getInstance(props);

        var message = _java.MimeMessage(session);
        message.setSender(
            new _java.InternetAddress("myEmailAddress", "My Full Name")
        );
        message.setRecipients(
            _java.Message.RecipientType.TO,
            [new _java.InternetAddress("anyAddress@anydomain.com", true)]
        );
        message.setText("Testing");
        message.setSubject("Test");
        message.setSentDate(new Date());
        var t = session.getTransport("smtp");
        t.connect(myUserName, myPassword);
        t.sendMessage(message, message.getAllRecipients());

The email that comes through has:

Sender: Personal Name <email@domain.com>

But the from is always:

From: email@domain.com

Therefore, mail clients like Outlook and Gmail aren't plucking out the name.

I've tried adding

props.put("mail.smtp.from", "Full Name <email@domain.com>")

but this doesn't make any difference.

Anybody have any experience with this bug?

Thanks.

Answers


What a pain.

The bug was that I was using message.setSender instead of message.setFrom.

Changing that solved it.


Need Your Help

performSelector:withObject:afterDelay: not queuing selector

ios objective-c grand-central-dispatch nsrunloop

I've setup a block to run on a different queue and call another method after a delay:

Passing int array to fragment shader

arrays opengl-es glsl fragment-shader

I'm attempting to plot an iterative function in OpenGL ES. An array of ints is being updated with how often a given pixel is hit by the iterative function. I'd like to pass this density array to a

Duck type as syntactic sugar for reflection: Good or bad idea?

refactoring language-design syntactic-sugar duck-typing

I've been thinking lately, would it be a good form of syntactic sugar in languages like Java and C#, to include a "duck" type as a method parameter type? This would look as follows: