0

I have successfully setup the postmark API in my rails dev environment and am trying to embed metadata containing record ID so I can process the record in my webhook. I receive a response from postmark into my webhook URL upon email delivery, but the application log shows the metadata blank. I have tried entering the metadata in hash notation as well but to no avail:

Processing by WebhooksController#create as HTML
  Parameters: {"MessageID"=>"b0c2673e-9628-4725-b9bb-xxxxxxxxxxxx", "Recipient"=>"nnnn@eee.ddd", "DeliveredAt"=>"2022-02-13T08:46:30Z",
"Details"=>"smtp;250 OK id=1nJAWV-001Lmg-Eu", "Tag"=>"", "ServerID"=>nnnnnnnnnn, "Metadata"=>{}, "RecordType"=>"Delivery", 
"MessageStream"=>"outbound", "token"=>"xxxxxxxxxxxxx", "webhook"=>{"MessageID"=>"b0c2673e-9628-4725-b9bb-xxxxxxxxxxxx", 
"Recipient"=>"nnnn@eee.ddd", "DeliveredAt"=>"2022-02-13T08:46:30Z", "Details"=>"smtp;250 OK id=1nJAWV-001Lmg-Eu", "Tag"=>"", 
"ServerID"=>nnnnnnnnnn, "Metadata"=>{}, "RecordType"=>"Delivery", "MessageStream"=>"outbound"}}

My mail block is as follows:

    mail(
      from: @invoice.account.company_email,
      to: @invoice.email,
      cc: @invoice.also_email,
      subject: "Invoice %s has been generated." % [@invoice.to_s],
      metadata: { "invoice_id": "bd2533a8-c00b-4830-97dc-xxxxxxxxxx" },
      message_stream: 'outbound',
      body: email_body
    ) do |format|
      format.html {email_body}
    end

As can be seen, I'm presently hard coding the id into the metadata while I try to solve this issue.

Interestingly, when I use the Postmark test stream, and view the raw data of the email, the metadata is showing (excerpt only):

metadata: {:invoice_id=>"bd2533a8-c00b-4830-97dc-xxxxxxxxxx"}
Feedback-ID: snnnnnn-_:snnnnnn:a22nnnn:postmark
X-Complaints-To: abuse@postmarkapp.com
X-Job: 227735_860nnnn

In addition to the metadata issue, I am receiving only delivery responses. I have open tracking enabled at the server level but aren't receiving any.

Any help would be greatly appreciated and thanks in advance. Oh, and I'm using the postmark-rails gem in rails in conjunction with actionmailer.

Lloydo
  • 303
  • 1
  • 8
  • Can you see the metadata displayed on Postmark's UI? "Metadata added to a message will be displayed in the Postmark UI, available using our API". – Shane Feb 13 '22 at 11:22
  • hmmm...not sure you say my earlier 'yes' response to that (deleted)...to clarify, yes I could see it when viewing the raw data under the Raw tab. I just found out it's supposed to show on the main page where postmark shows the email and its events. No, the metadata does not show there. I also just stumbled across another wildbit page referring to adding metadata and it's outside the mail block. I will try this. Thx. – Lloydo Feb 13 '22 at 21:43

1 Answers1

0

Issue has been resolved. The metadata should be inserted outside the mail block as an array:

https://github.com/wildbit/postmark-rails/wiki/Email-sending

Lloydo
  • 303
  • 1
  • 8