ruby-on-railsruby-on-rails-5sendgridemail-deliverysendgrid-rails

Rails, How to deliver dynamic email depending on user status after session expiration


So I have a website similar to an e-commerce site. I want to send out an email to the user after session expiry(preferably 30min after expiry), with dynamic content - with respect to their status, i.e. if they have items in their cart, if they haven't paid, or if the payment was successful.

So there are three questions here?

Currently, I'm using Rails 5.0.0, and sendgrid to send emails. Sendgrid has codes like Mail.deliver_after(30 mins). But I can't seem to put an if else condition to make the content of the email dynamic. Also, I want to send the email after 30 mins after session expiry.


Solution

  • What are different ways to achieve this?

    - Using background job. Create asynchronous jobs with run time and priority.
    

    Is it possible to run a section of code after 30min of session expiration?

    - Use delayed_job gem or use some other background job gems. Using asynchronously
    

    Is it possible to put an if-else statement to the mail delivery depending on the user status?

     - Called mail delivery using background job so you can send mail whenever you want.