0

Action mailer sends email through sendgrid with smtp settings, I can get delivery confirmation by sengrid's webhook, and some emails delivered to sengrid, some - looks like not, for example we sent 100 emails and sendgrid said that they got 97, so 3 just disappeared

Maybe there is way to get confirmation in mailer's action in after action callback?

1 Answers1

0

you can use after_action

Please check the following example :

class YourMailer < ActionMailer::Base
  after_action :check_email_delivery, only: [:your_action]

  def your_action
    # Your email generation code
  end

  private

  def check_email_delivery
    # Implement your custom logic to check email delivery status here
    # You can use SMTP libraries or services to verify the delivery
    # For example, you can use the `smtp_mail` gem to check delivery status

    # Update your database or perform other actions based on the delivery status
  end
end
Ronak Bhatt
  • 113
  • 1
  • 2
  • 14
  • Thanks, but this example is totally clear, and in general I have it. So I need examples of check_email_delivery method and what exact smtp_mail gem did you mean? – Anton Bogdanov May 29 '23 at 10:18