Is it possible to change the message-id in postfix? If I send Mails over an Java-Application I get the following message-id:
message-id=<143303043.111334605578921.JavaMail.applicationanme@hostname>
So I want that the message-id looks like this:
message-id=<[email protected]>
What I can understand, if I send mails with the Linux program mail
it works:
message-id=<[email protected]>
I have already set my hostname in the postfix-conf, but when I send a mail with the java-application it doen't work. We use a relay host to send email and any messages which are sent without @domain.tld
in the mail-id will detected as a spam mail.
Do you have any idea how I can fix this?
Since no one gave you a solution on how to have postfix insert a message-id that reflects your domain and I had the same issue, I figured I would share how I was able to have postfix do so:
Add to the end of
/etc/postfix/main.cf
header_checks = regexp:/etc/postfix/header_checks
Insert a replace string in
header_checks
/Message-Id:\s+<(.*?)@hostname>/ REPLACE Message-Id: <[email protected]>
Run postmap
postmap /etc/postfix/header_checks
Restart postfix
service postfix restart
Instead of trying to rewrite the message ID in postfix, why not just have javamail generate the correct MessageID from the start. You can change how javamail generates MessageID by subclassing
MimeMessage
and providing a newupdateMessageID
methodWhy do you want to do this? As @BenPilbrow pointed out, the message-id is next to meaningless. Pretty much the only thing that will use it is a threading e-mail client.
As @stew pointed out, you can just emit an email with a proper message ID in the first place.
Finally, the postfix solution is to change the value of the $myhostname, as this is what postfix uses after the @ symbol when it creates message ids.
The relevant java property is
mail.host
. Depending on your application you may have a property file where you set it like:alternatively using command-line -D option:
As others have pointed out, the domain part in message-id is almost 100% irrelevant - except for the spam case. I had a similar problem where messages sent via
mail
program were delivered immediately but those sent via javamail, which omitted TLD from the message-id got delayed delivery only. The problem was fixed by adding the full TLD to the message-id.