0

Im trying to send emails on a rake task in my app. My mailer works perfectly with the server, but when running on a rake task it does nothing.

Here is my rake task:

namespace :booking do
  desc "Send an email about a upcoming job to the clients"
  task :send_email_upcoming_job_forty_eight => :environment do
    begin 
      puts("Im sending email forty eight with the class #{AdminMailer}")
      AdminMailer.notify_client_accepted("[email protected]gmail.com")
      puts("Finished")
    rescue StandardError => e
      puts e
    end
  end
end

And here are my AdminMailer method:

def notify_client_accepted(email)
  puts("Sending client_acepted #{email}")
  data = JSON.parse('{
    "personalizations": [
      {
        "to": [
          {
             "email": "'+email+'"
          }
        ],
         "dynamic_template_data": {
          "subject": "Testing Templates",
          "login_url": "'+root_url+'"
        }
      }
    ],
    "from": {
      "email": "[email protected]"
    },
    "content": [
      {
        "type": "text/plain",
        "value": "Admin Mailer"
      }
    ],
    "template_id": "d-e02e093acf424728b191b776daeecec8"
  }')
  puts data
  self.send_sendgrid_email(data)

end

When I run: rake booking:send_email_upcoming_job_forty_eight

I got from console:

Im sending email forty eight with the class AdminMailer
Finished

But the email never arrives. And the "puts" inside the AdminMailer arent printed on console too

Any ideia why? (remembering. AdminMailer works perfectly in my app. The rake task isnt)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.