How to set hostname used in JavaMail or Apache James Message-Id header?

572 views Asked by At

I am having issues with mail bouncing when sending from my own server to my own active yahoo account using JavaMail. The mails are passing SPF, DKIM and DMARC according to google mail that receives the same messages being bounced by yahoo. I can send messages from other accounts to my yahoo account without issue.

The messages send fine from my server to ZMail, GMail, Microsoft mail. Looking at the emails, the only thing that I have noticed is the message header for the Message-Id. My messages have the following header:

Message-ID: <923936395.17.1634776639078@[internally visible hostname]>

I am wondering if this header could be the problem and whether there is a way in JavaMail or in the Apache James to set the hostname or IP address that gets used in this message so that rather than using the "internally visible hostname", I can get the hostname that is externally visible. I have been searching the available documentation for Apache James and JavaMail but have not found any parameters to try in order to resolve this.

1

There are 1 answers

0
cs8898 On

According to the Decompiled SRC of sun mail it should be possible by setting some properties for your session.

props.setProperty("mail.from", user);
props.setProperty("mail.host", host);
//props.setProperty("mail.user", user);

The Id will be updated by the save method (saveChanges()) and will trigger an new ID generation (updateHeaders() -> updateMessageID()). (Looked up in the decompiled MimeMessage.class)
Leading to the HostPart called in javax.mail.internet.InternetAddress.
The relevant method is _getLocalAddress.

Here you can see that the values get extracted from the Properties or will fallback to your local machine.

Used Fields:

  • user.name
  • mail.from
  • mail.user
  • mail.host

The user.name property can also be looked up from the system props.