I have rails application running, which send emails using postfix as relay. Here is flow

Rails -> Resque workers -> Postfix -> SES -> email out to clients

my problem is i want to find relation between logs of rails and postfix, to ensure that not even single email is lost and properly sent to recipient.

for example, if rails logs show, email is sent to "Abc@abc.com" then i can check in logs that email is sent to abc@abc.com, and i want to check the same email in postfix too. Ofcourse it will have an entry there, but to be precise and accurately find that if that specific email was sent using postifx or not? like a recipient can send 100 emails to abc@abc.com, or may be 50, with different interval of time, so how can i add any special TAG, an ID , or anything in the rails app, that i can trace it in the postifx logs?

I hope problem is clear.



If your Rails uses SMTP for connections to Postfix, you are interested in the 250 response:

250 2.0.0 Ok: queued as 41F1A40412

If you get your Rails to log this ID, it's easy to find from Postfix logs what happened to it later:

$ grep 41F1A40412 /var/log/mail.log

postfix/smtpd[1900]: 41F1A40412: client=localhost[]
postfix/cleanup[1903]: 41F1A40412: message-id=<20180324110311.41F1A40412@example.com>
postfix/qmgr[29213]: 41F1A40412: from=<user@example.com>, size=299, nrcpt=1 (queue active)
postfix/smtp[1904]: 41F1A40412: to=<recipient@example.net>, 
    relay=example.net[]:25, delay=14, delays=13/0.07/0.26/0.71, dsn=2.0.0, 
    status=sent (250 2.0.0 OK 5D47140412)
postfix/qmgr[29213]: 41F1A40412: removed

At least the deliver.now! method shows this response as it forces the immediate send. If this doesn't happen with the normal deliver method that's probably because SMTP by design is unambiguous of who has the responsibility of delivering the message: it should only get removed from any queue when the next hop accepts the responsibility with the very 250 Ok response.

| improve this answer | |
  • 1
    As you can see, Postfix queued the message as 41F1A40412 and you can track it by that ID. Then, the next hop accepted the message with ID 5D47140412. The previous hop can only be aware of the internal message ID of the next hop. But they are unique and can be used for tracking the message. – Esa Jokinen Mar 24 '18 at 11:29
  • actually Rails is not using smtp. :( – Farhan Mar 24 '18 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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