【发布时间】:2018-11-16 22:01:04
【问题描述】:
我们正在尝试将我们的设计密码重置表单链接到 mailjet gem。我已按照 mailjet 存储库自述文件中的所有说明进行操作,但我仍然无法将 API 连接到 Devise“重置密码”表单,而且似乎很明显缺少某些内容。
a) 首先,我在 google、mailjet 的支持网站和 Stackoverflow 上到处搜索,但似乎找不到任何帮助将 MailJet 连接到 Devise 的说明。我错过了什么吗?
b) 如果没有关于如何执行此操作的预先编写的指南,是否有人可以帮助我执行我需要采取的特定步骤,以确保当我在我们的设计登录页面上按“发送密码重置链接”时,它正确地发送电子邮件?现在,我们收到一个错误:需要电子邮件。但我的电子邮件地址在那里。所以它没有正确连接。我认为我们需要将该特定设计页面连接到 mailjet api,但我不确定如何做到这一点。
c) 接下来,这是在 localhost 上可测试的,还是在 heroku 上进行测试的唯一方法?也许这可能是问题之一......
d) 最后,我是否必须在 Heroku 本身上做任何事情才能链接到我的 MailJet 帐户?显然,您使用 SendGrid,但我认为因为我已经有了 mailjet API 和 Secret Key,我不需要直接通过 Heroku 连接,是吗?
提前感谢您的帮助。 -梦露
到目前为止,这是我的代码:
密码重置页面
<main class="form forgot-form">
<section class="form-container">
<h1>Reset password</h1>
<p>Enter the email address associated with your account, and we’ll email you a link to reset your password.</p>
<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }, :defaults => { wrapper: false }) do |f| %>
<%= f.error_notification %>
<%= f.input :email, required: true, autofocus: true, error: 'Email is required',
input_html: { class: 'form__field' }, label_html: { class: 'sr-only' }, placeholder: 'Email Address' %>
<%= f.button :submit, "Send reset link", class: 'form__button mt-4' %>
<% end%>
<%= link_to '< Back to Login', new_user_session_path, class: "link go-page" %>
</section>
</main>
邮寄者本身:
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
初始化器:
# kindly generated by appropriated Rails generator
Mailjet.configure do |config|
config.api_key = 'my-api-key--removed for safety'
config.secret_key = 'my-secret-key--removed for safety'
config.default_from = 'my-email--removed for safety'
# Mailjet API v3.1 is at the moment limited to Send API.
# We’ve not set the version to it directly since there is no other endpoint in that version.
# We recommend you create a dedicated instance of the wrapper set with it to send your emails.
# If you're only using the gem to send emails, then you can safely set it to this version.
# Otherwise, you can remove the dedicated line into config/initializers/mailjet.rb.
config.api_version = 'v3.1'
end
开发.RB
# Specify that we are using the MailJet API for transactional emails
config.action_mailer.delivery_method = :mailjet
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
PRODUCTION.RB
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "bdcommunity_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
#Set this to true and configure the email server for immediate delivery to raise delivery errors.
#NOTE FROM MONROE: We should look into this after we launch and as we develope the site further
#config.action_mailer.raise_delivery_errors = false
# Specify that we are using the MailJet API for transactional emails
config.action_mailer.delivery_method = :mailjet
# config.action_mailer.perform_deliveries = true
上面的“perform_deliveries”是我在 2011 年的一篇文章中发现的,所以它很可能不起作用。我只是把它放在那里(注释掉),以防它可以帮助你找出我们做错了什么。
【问题讨论】:
标签: ruby-on-rails heroku devise mailjet