How to get email reply sent using sendgrid in rails application to save to database

I sent email through the rails app using sendgrid and actionmailer, I also received mail. But I want the email sent (open, delivered, rebound ..) to sendgrid in my rails application so that I can save this reply to a specific email in my database.

I followed: https://github.com/stephenb/sendgrid to send emails and it worked for me.

+4
source share
2 answers

To get the status of the sent email, use the webgooks sendgrid as described here

Once this is installed, sendgrid will notify your URL of the following events:

  • Processed: Message received and ready for delivery.
  • Dropped: The recipient exists in one or more of your suppression lists: rebounds, spam reports, unsubscribe.
  • Delivered: message successfully delivered to the receiving server.
  • Delayed: The mail server recipient has temporarily rejected the message.
  • Failure: the receiving server could not or did not receive the message.
  • Open: The recipient opened the HTML message.
  • Click: Recipient clicked the link in the message.
  • Spam Report: Recipient marked as spam.
  • Unsubscribe: The recipient clicked on the message subscription management link.
+2
source

You must set up an event website for your application. Once you do this, you will receive a POST for your application in the format:

{ "email":" foo@bar.com ", "timestamp":1322000095, "unique_arg":"my unique arg", "category": "some_category", "event":"delivered" } 

Since you are using Rails, you should also check out the GridHook . SendGrid does not officially support it, but there are a few people in the open source developer community. With this, you can do something like:

 Gridhook.configure do |config| # The path we want to receive events config.event_receive_path = '/sendgrid/event' config.event_processor = proc do |event| # event is a Gridhook::Event object EmailEvent.create! event.attributes end end 
+1
source

All Articles