我在发送一些电子邮件时遇到问题,而其他电子邮件似乎工作正常。
似乎当我使用我的视图时他们没有发送,这是我定义的一封邮件,它只是传递了一个发送就好了的正文
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
这是welcome
看起来像..这个不起作用..
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
这是我在日志中得到的
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>>
看起来好像邮件已生成,我正在调用deliver_now
响应,但它从未通过...进入收件箱mailjet
......难道是视图的内容如何阻止它发送?
我正在使用rails 4.2.8
和ruby 2.4.0
提前致谢!
编辑这是我的 action_mailer 配置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
使用 API 的密钥和秘密定义,并且gem 'mailjet'
位于Gemfile