9

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=<143303043.111334605578921.JavaMail.applicationanme@domain.tld>

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

message-id=<10213429251967.C2D74C1A8D@domain.tld>

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?

Ben Pilbrow
  • 11,995
  • 5
  • 35
  • 57
Marcus
  • 91
  • 1
  • 1
  • 2
  • 2
    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
  • 5
    Because "hostname" is "ihateyouall" or "asskickr" whereas "domain.tld" is "jesus-loves-you.org" – mailq Nov 30 '11 at 00:01
  • This is a solution without a problem. – MikeyB May 27 '14 at 00:46

4 Answers4

13

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/main.cf

    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

pevik
  • 286
  • 1
  • 12
thezilla
  • 131
  • 1
  • 2
9

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

stew
  • 9,263
  • 1
  • 28
  • 43
  • 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 01 '11 at 20:18
  • 2
    @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 01 '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 01 '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 01 '11 at 20:28
5
  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.

Flimzy
  • 2,375
  • 17
  • 26
2

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

mail.host=your.tld

alternatively using command-line -D option:

java -Dmail.host=your.tld ...

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.