Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to change the message-id in postfix? If I send Mails over an Java-Application I get the following message-id:


So I want that the message-id looks like this:


What I can understand, if I send mails with the Linux program mail it works:


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?

share|improve this question
It's a message id. An internal identifier. NOBODY looks at the message id unless they're debugging an email problem. Even then, we sure as hell don't care whether it's @hostname or @tld, we just care why there is a problem causing us to look at the damned ugly thing in the first place. Why do you care so much? – Ben Pilbrow Nov 29 '11 at 21:31
Because "hostname" is "ihateyouall" or "asskickr" whereas "domain.tld" is "" – mailq Nov 30 '11 at 0:01
This is a solution without a problem. – MikeyB May 27 '14 at 0:46

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 new updateMessageID method

share|improve this answer
Or better setting the system wide (Java) properties for hostname and domain. Postfix has absolutely nothing to do with Message-IDs! – mailq Nov 29 '11 at 23:58
@mailq: That's simply not true. Postfix does set the Message-ID in certian cases when it is omitted (which is often the case for system-generated mail, such as comes from cron, or other system processes.) – Flimzy Dec 1 '11 at 20:18
@Flimzy That's not true. The variable always_add_missing_headers defaults to no. You have to set it explicitly. And if a Message-ID is present then it will not change it (as it is not allowed to change). And as you see, the JavaMail already set the ID. – mailq Dec 1 '11 at 20:23
@mailq: Read the description for that option more closely. Postfix 2.6 and later add these headers only when clients match the local_header_rewrite_clients parameter setting. Even with always_add_missing_headers off, Message-ID is still added when the message matches local_header_rewrite_clients (which by default means hosts match inet_interfaces). – Flimzy Dec 1 '11 at 20:26
@mailq: And I never said that postfix would overwrite a Message-ID; I'm simply taking issue with your statement that "postfix has absolutely nothing to do with Message-IDs!" That statement is patently false. – Flimzy Dec 1 '11 at 20:28
  1. Why 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.

  2. As @stew pointed out, you can just emit an email with a proper message ID in the first place.

  3. 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.

share|improve this answer

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:

1) Add to the end of /etc/postfix/

header_checks = regexp:/etc/postfix/header_checks

2) Insert a replace string in header_checks

/Message-Id:\s+<(.*?)@hostname>/ REPLACE Message-Id: <$1...@domain.tld>

3) Run postmap

postmap /etc/postfix/header_checks

4) Restart postfix

service postfix restart
share|improve this answer

The relevant java property is Depending on your application you may have a property file where you set it like:

alternatively using command-line -D option:

java ...

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.