Ruby on rails Rails 4 Mailchimp Mandrill带装置
我正在尝试使用Desive和manrill/mailchimp(合并)帐户设置Rails 4 我想从我的mailchimp/mandrill帐户发送一封设计确认电子邮件 我的heroku日志显示以下消息:Ruby on rails Rails 4 Mailchimp Mandrill带装置,ruby-on-rails,devise,mailchimp,mandrill,Ruby On Rails,Devise,Mailchimp,Mandrill,我正在尝试使用Desive和manrill/mailchimp(合并)帐户设置Rails 4 我想从我的mailchimp/mandrill帐户发送一封设计确认电子邮件 我的heroku日志显示以下消息: MandrillDeviseMailer#confirmation_instructions: processed outbound mail in 504.2ms 但是我没有收到电子邮件 我不知道如何设置我的code/mandrill/mailchimp帐户 我有一封邮件如下: class
MandrillDeviseMailer#confirmation_instructions: processed outbound mail in 504.2ms
但是我没有收到电子邮件
我不知道如何设置我的code/mandrill/mailchimp帐户
我有一封邮件如下:
class MandrillDeviseMailer < Devise::Mailer
default from: "hello@testhub.com"
require "mandrill"
def confirmation_instructions(record, token, opts={})
# code to be added here later
options = {
:subject => 'Confirm your account',
:email => record.email,
:name => record.formal_name,
:global_merge_vars => [
{
name: 'email',
content: record.email
},
{
name: 'confirmation_link',
content: record.confirmation_token
}
],
:template => 'devise-confirmation-instructions'
}
mandrill_send(options)
end
def reset_password_instructions(record, token, opts={})
options = {
:subject => "Reset your password",
:email => record.email,
:global_merge_vars => [
{
name: "password_reset_link",
content: "http://www.testhub.com/users/password/edit?reset_password_token=#{token}"
},
{
name: "PASSWORD_RESET_REQUEST_FROM",
content: record.full_name
}
],
:template => "Forgot Password"
}
mandrill_send options
end
def unlock_instructions(record, token, opts={})
# code to be added here later
end
def mandrill_send(opts={})
message = {
:subject=> "#{opts[:subject]}",
:from_name=> "Welcome aboard",
:from_email=>ENV["OD_WELCOME"],
:to=>
[{"name"=>"#{opts[:formal_name]}",
"email"=>"#{opts[:email]}",
"type"=>"to"}],
:global_merge_vars => opts[:global_merge_vars]
}
sending = MANDRILL.messages.send_template opts[:template], [], message
rescue Mandrill::Error => e
Rails.logger.debug("#{e.class}: #{e.message}")
raise
end
end
我不知道如何在mandrill/mailchimp中设置电子邮件模板,以使这些变量工作
我尝试了几种变体,但是没有用动态输入填充变量,而是用管道、ruby标记和文本发送电子邮件,这些应该作为代码来编写
在我的mailchimp模板中,我有:
嗨
您可以通过以下链接确认您的帐户电子邮件:
它以文本的形式出现在上面。我还尝试将ruby标记放入| |标记中,但这些标记也只是打印出来
有人知道怎么设置吗
进一步尝试
我还尝试将mail chimp模板设置为使用合并标记,如下所示:
|密码重置链接|
当我在生产中尝试此功能时,它会发送一封电子邮件,邮件正文中会打印以下内容:
<a href="*|password_reset_link|*">Change my password </a>
/app/mailers/mandrill_devise_mailer.rb
require "mandrill"
class MandrillDeviseMailer < Devise::Mailer
default(
from: "email@yourdomain.com",
reply_to: "email@yourdomain.com"
)
def reset_password_instructions(record, token, opts={})
subject = "Password reset link from Your App"
# These become available in your Mailchimp template and can be used
# using the usual *|DISPLAY_NAME|*
merge_vars = {
"PASSWORD_RESET_LINK" => "https://www.yourdomain.com/users/password/edit?reset_password_token=#{token}",
"DISPLAY_NAME" => record.display_name || record.email
}
# The name of your template in Mailchimp
# make sure to "send to mandrill" from the edit dropdown
body = mandrill_template("Password Reset Template", merge_vars)
send_mail(record.email, subject, body)
end
private
def send_mail(email, subject, body)
mail(to: email, subject: subject, body: body, content_type: "text/html")
end
def mandrill_template(template_name, attributes)
mandrill = Mandrill::API.new(ENV["SMTP_PASSWORD"])
merge_vars = attributes.map do |key, value|
{ name: key, content: value }
end
mandrill.templates.render(template_name, [], merge_vars)["html"]
end
end
designe.rb
初始值设定项更改,需要如下所示:
config.mailer_sender = "email@yourdomain.com"
# Configure the class responsible to send e-mails.
config.mailer = 'MandrillDeviseMailer'
你说你还没有收到消息,但是消息是发送的吗?您应该检查Mandrill控制台以查看是否正在发送消息。他们可能会进入你的垃圾邮件文件夹。
# /config/environments/production.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: ENV["SMTP_ADDRESS"],
authentication: :plain,
domain: ENV["SMTP_DOMAIN"],
enable_starttls_auto: true,
password: ENV["SMTP_PASSWORD"],
port: "587",
user_name: ENV["SMTP_USERNAME"]
}
config.action_mailer.default_url_options = { host: ENV["SMTP_DOMAIN"] }
config.mailer_sender = "email@yourdomain.com"
# Configure the class responsible to send e-mails.
config.mailer = 'MandrillDeviseMailer'