20

I have suspicious message-id header of email sent by php to gmail account:

Message-Id: <5100054f.a489440a.5d93.6a70SMTPIN_ADDED_MISSING@mx.google.com>

Could you please tell does it have this strange format and what SMTPIN_ADDED_MISSING means here? Examples I saw in the internet had format something like this containing sending domain but my message id doesn't contain it for some reason:

38D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com

I don't think I set this header in Zend_Mail. What generates this headers? Do you see any issues with this header?

Oleg
  • 2,733
  • 7
  • 39
  • 62

6 Answers6

25

A proper outbound email client should be generating the Message-ID header when the email is sent. Google is being 'nice' and generating it for you when the message passes through its email system, but most won't, and most spam filters will take this missing header as an indication that the message is more likely to be spam. Any malformed or missing headers will add to the "spam score".

It is not difficult to generate, all that is required is that it is unique per-message:

$message-id = time() .'-' . md5($sender . $recipient) . '@' $_SERVER['SERVER_NAME'];

Or

$message-id = time() .'-' . md5($sender . $recipient) . '@yourdomain.com';

Gives:

1358961017-677533f745f613447d06de25e7fa4d32@yourdomain.com
Sammitch
  • 30,782
  • 7
  • 50
  • 77
8

Google SMTP generates it if missing. This header must be set by the first SMTP server. So you do not generate it - google does. It is used to prevent multiple delivery and to link related messages together.

It is not required to set message id header, but it's like a good practice for most (but not all, only configured) smtp to add (may be fix) this header. So to avoid generation of this header by others you can generate it by yourself.

clover
  • 4,910
  • 1
  • 18
  • 26
  • 1
    Should I set it from php or should server smpt server add them? Should message_id contain domain of server that sends address something like this: 8D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com? – Oleg Jan 23 '13 at 16:58
  • Do you mean that if there is not message id in sent email, receving email generate it and adds to the message? – Oleg Jan 23 '13 at 17:09
  • SMTP server generates it when it does not exists. It's not necessery to generate from PHP. It muse include @domain part. Recommendations http://www.jwz.org/doc/mid.html – clover Jan 23 '13 at 17:17
  • If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it. – Oleg Jan 24 '13 at 04:16
  • Is it possible to configure SMTP server to add message id automatically not to send it in application? – Oleg Jan 24 '13 at 10:37
  • yes, postfix for example: always_add_missing_headers (default: no) – clover Jan 24 '13 at 22:25
4

This one works for me (I also added a 'Date' line to the header because it was a spam issue to me as well). Based on this peace of code.

Here's my PHP array approach (using Pear's Mail and Mime libraries):

$headers = array(
   'From'       => $from,
   'Subject'    => $subject,
   'To'     => $to,
   'Cc'     => '',
   'Date'       => date('r'),
   'Message-ID' => sprintf("<%s.%s@%s>",
                                base_convert(microtime(), 10, 36),
                                base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36),
                                'yourdomain.com')
                );

Note that using $_SERVER['SERVER_NAME'] instead of literally 'yourdomain.com' won't work in php cli as commented out by Oleg on another answer.

Heitor
  • 683
  • 2
  • 12
  • 26
0

I am using same MessageId to track the exchanged messages.

I fix the MessageId with:

$mail->MessageID =sprintf('<%s@%s>', $myMessageID, 'myserver');
nobody
  • 19,814
  • 17
  • 56
  • 77
0

tl;dr; Do not use port 25 when sending email instead use port 587

When I was sending outbound email from my custom created golang email client using port 25 to my local postfix server with destination email address either gmail or google gsuite adddress I was seeing

Message ID  <5be55db9.1c69fb81.d0444.d894SMTPIN_ADDED_MISSING@mx.google.com>

as viewed from destination email adddress in gmail Show Original ... However since I am using full TLS certs in both my golang email client and local postfix server, when I replace using port 25 with the secure port 587 in my outbound email client (postfix was already using TLS certs) then I get the proper

Message ID  <20181109163255.F164D8E9588@mail.myexample.com>

NOTE - at no time am I defining an email header message-id infact the golang repo I'm using does not have an api call to define that header

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
0

You missed the '<' and '>' brackets.

Antony Hatchkins
  • 31,947
  • 10
  • 111
  • 111