Skip to content

Accessing Postmark Message ID

Igor Balos edited this page Jul 5, 2021 · 11 revisions

Each email message sent by Postmark will contain a unique Postmark message ID. In case of email messages, identifier is stored within X-PM-Message-ID header.

This identifier can be used to for things like retrieving bounce details later.

The example below shows you how to access the Postmark Message ID from sent email headers. Keep in mind that this header will be sent once the email is sent to Postmark for delivery, not before.

server_token = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
client = Postmark::ApiClient.new(server_token)

message = Mail.new
# ...
client.deliver_message(message)
message['X-PM-Message-ID'].to_s

# => cadba131-f6d6-4cfc-9892-16ee738ba54c

In case of using Rails ActionMailer , retrieving identifier by X-PM-Message-ID header is the way to go.

You can also access Postmark message ID from sent email response. In this case, identifier is accessible by :message_id.

client.deliver({from: '[email protected]', to: '[email protected]', html_body: 'test', subject: 'Welcome email'})

# => {:to=>"[email protected]",:submitted_at=>"2021-07-05T12:55:25.6949168Z",:message_id=>"123456-111c-111-1234567890",:error_code=>0,:message=>"OK"}

Postmark message id is stored within "X-PM-Message-ID" header, not "Message-ID" header of the email sent for reason of not altering any identifiers which are not Postmark related. Postmark related headers will always start with "X-PM" to not interfere any other headers.