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

Java 8 - Default methods for equals and hashcode

equals java-8 hashcode behavior default-method

I have created default methods in an interface for implementing equals and hashcode in predictable manner. I use reflection to iterate all fields in a type (class) to extract the values and compare...

Highlighting a row in a JSF page is not working

java javascript jquery html jsf-2

I want to highlight a row in a JSF table. This is the code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.