3

I am having an issue sending some emails, while others seem to work fine.

it seems like when i am using my views they are not sending, here is an a mail i have defined that just passes a body that sending just fine

def send_contact_email params
  mail({from: params[:email],
          to: 'inquiries@gmail.ca',
          body: params[:message],
          content_type: "text/html",
          subject: "Inquiry from [#{ params[:name] }]"})
end

UserMailer.send_contact_email(params).deliver_now

here is what welcome looks like..this one does not work..

def welcome user, token
  @resource = user
  @token = token
  mail({ to: user.email,
          content_type: "text/html",
          subject: "Thankyou!"})
end

UserMailer.welcome(u,hashed_token).deliver_now

here is what i get in the logs

UserMailer#welcome: processed outbound mail in 13.9ms

Sent mail to email@gmail.com (10364.1ms)
Date: Sat, 25 Nov 2017 19:39:19 +1100
From: no-reply@gmail.cl
To: email@gmail.com
Message-ID: <5a192c37982fc_a9663ff3cec3e51845790@mac.local.mail>
Subject: Gracias!
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>The Project | Email Template</title>
  </head>
  <body style="margin: 0; padding: 0;">
    <p>Hola email@gmail.com!</p>

<p>Se ha solicitado cambiar tu contrasena. Puedes hacerlo a traves del siguiente link.</p>

<button style="color:white; background:#FF5722; border:0; border-radius:0; padding:15px; font-size:16px;"><a style="color:white; text-decoration: none;" href="http://localhost:3000/users/password/edit?reset_password_token=a9d57947ffb8c077a2b58239d0c6afec91e7c7bb9424c36cb362d6682341c086">Cambiar contrasena</a></button>

<p>Si no lo solicito, ignore este correo electronico.</p>
<p>Su contrasena no cambiara hasta que acceda al link de arriba y cree una nueva.</p>

  </body>
</html>

=> #<Mail::Message:70316446670780, Multipart: false, Headers: <Date: Sat, 25 Nov 2017 19:39:19 +1100>, <From: no-reply@gmail.cl>, <To: email@gmail.com>, <Message-ID: <5a192c37982fc_a9663ff3cec3e51845790@mac.local.mail>>, <Subject: Gracias!>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: 7bit>>

it appears as though the mail gets generated, I am calling deliver_now on the response, but it never hits the inbox via mailjet...could it be the content of the view that is some how keeping it from delivering?

I am using rails 4.2.8 and ruby 2.4.0

Thanks in advance!

EDIT this is my action_mailer config from development.rb

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.perform_deliveries = true
config.action_mailer.preview_path = "#{Rails.root}/test/mailers/previews"
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost', :port => 3000 }
config.action_mailer.delivery_method = :mailjet

config/initializers/mailjet.rb is defined with the key and secret for the API and gem 'mailjet' is in the Gemfile

raddrick
  • 4,274
  • 2
  • 27
  • 33
  • What environment are you facing this issue in? Can you post the config file for that environment, e.g., **config/environments/development.rb**? – inveterateliterate Nov 25 '17 at 17:20
  • @inveterateliterate see **Edit** – raddrick Nov 25 '17 at 23:30
  • It cant be a config issue because `send_contact_email` works as expected! The issue is only when I am using a view for the email. – raddrick Nov 25 '17 at 23:44
  • what does the log of mailjet tell you about that mail? – Oliver Dec 02 '17 at 13:37
  • @Oliver it never hits mailjet. i dont know of any log persay, but on the stats page, you can see the `send_contact_email` getting managed, but nothing for the `welcome` email. is there an actual mailjet log available somewhere from their web portal? i will have a look around to see if i can find it in their dev section – raddrick Dec 03 '17 at 02:55
  • @RGB maybe you should try using localhost as mta for testing. install postfix or something like that and see what happens. – Oliver Dec 03 '17 at 15:00
  • i was using mailcatcher in local host and they appear find over smtp. i will try and tinker around with postfix to see what it shows me – raddrick Dec 04 '17 at 09:03
  • @RGB I think you need to configure below seeting in development.rb file `ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port => 587, :authentication => :plain, :domain => 'gmail.com', :user_name => Env.gmail.user_name, :password => Env.gmail.password } end ` – Kinjal Shah Dec 05 '17 at 10:53
  • that sets the smtp to gmail for sending the emails, i want to use `:mailjet` – raddrick Dec 05 '17 at 18:17

0 Answers0