How to maintain log of email status sent using Pony gem in Sinatra

95 Views Asked by At

I am using Sinatra Ruby for API and using Pony gem for sending emails. I want to log status of every mail sent (whether email was successfully sent or not, to whom it was sent etc.). I see only routing log in Sinatra console, but no any sign of email. In short I want to maintain log as in rails console.

1

There are 1 best solutions below

0
Kelsey Hannan On

In the docs there are methods to see if an email has bounced:

Getting Error Reports from an Email:

@mail = Mail.read('/path/to/bounce_message.eml')

@mail.bounced?         #=> true
@mail.final_recipient  #=> rfc822;[email protected]
@mail.action           #=> failed
@mail.error_status     #=> 5.5.0
@mail.diagnostic_code  #=> smtp;550 Requested action not taken: mailbox unavailable
@mail.retryable?       #=> false

So when you send it you can run puts @mail.bounced? if you have access to the instance variable of the mail sent, otherwise find where the .eml message is saving.