dimanche 17 décembre 2017

i can't send email using smtp

So i made mailer using

rails g mailer UserMailer

My app/mailers/user_mailer.rb:

class UserMailer < ApplicationMailer
    default from: 'appointments@gmail.com'

    def accepted_appointment(customer)
        @customer = customer
        @user = User.find(@customer.user_id)
        @appointments = @user.appointments.includes(:employee)
        mail(to: @user.email, subject: 'Your appointment has beed accepted')
    end
end

My app/views/accepted_appoitnment.html.erb (I know its a bit empty but i wanted to just send something):

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Hello <%= @customer.first_name %>!</h1>
    <p>

    </p>
    <p>
      Thank you very much for using our services!
    </p>
    <p>Thanks for joining and have a great day!</p>
  </body>
</html>

And my config/environments/development.rb

Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.assets.debug = true
  config.assets.digest = true
  config.assets.raise_runtime_errors = true
  config.action_mailer.default_url_options = { host:
'localhost', port: 3000 }
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  # SMTP settings for gmail
  config.action_mailer.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :user_name            => "Myemail@gmail.com",
    :password             => "Mypassword",
    :authentication       => "plain",
    :enable_starttls_auto => true
  }
end

And nothing happens. My function where i call accepted_appointment(customer) just doing her work and everything is just great but mail is not sent. What have i done wrong?

Aucun commentaire:

Enregistrer un commentaire