问题
I have sent email through rails app using sendgrid and actionmailer, I also received the mail. But I want status of the email sent (open,deliver,bounce..) of sendgrid in my rails app so that that response of particular email i can save in my database.
I have followed: https://github.com/stephenb/sendgrid for sending email and it worked for me.
回答1:
To get status of sent email, use sendgrid webhooks as described here
Once this is setup, sendgrid will notify your url for the following events:
- Processed: Message has been received and is ready to be delivered.
- Dropped: Recipient exists in one or more of your Suppression Lists: Bounces, Spam Reports, Unsubscribes.
- Delivered: Message has been successfully delivered to the receiving server.
- Deferred: Recipient’s email server temporarily rejected message.
- Bounce: Receiving server could not or would not accept message.
- Open: Recipient has opened the HTML message.
- Click: Recipient clicked on a link within the message.
- Spam Report: Recipient marked message as spam.
- Unsubscribe: Recipient clicked on messages’s subscription management link.
回答2:
You should setup the event webhook for your app. Once you do, you'll get POSTs to your app in the format:
{
"email":"foo@bar.com",
"timestamp":1322000095,
"unique_arg":"my unique arg",
"category": "some_category",
"event":"delivered"
}
Since you're using Rails, you should also check out GridHook. SendGrid doesn't officially support it, but there are a number of people in the open source community working on it. With that, you'll be able to 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
来源:https://stackoverflow.com/questions/15476107/how-to-get-response-of-email-sent-using-sendgrid-in-rails-app-to-save-in-databas