这是我第一次在rails项目中设置邮件。 我被告知使用SparkPost并为多种动作创建不同语言的模板。Actionmailer - Sparkpost模板和多语言
为了简单起见,可以说一个user_signed_up(用户)邮件。
目前我有这样的设置工作:
宝石安装: 'sparkpost'
mail.rb
ActionMailer::Base.smtp_settings = {
address: "smtp.sparkpostmail.com",
port: 587,
enable_starttls_auto: true,
user_name: "SMTP_Injection",
password: SPARKPOST_API_KEY,
domain: 'foo-bar.com'
}
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.default charset: "utf-8"
application_mailer.rb
require 'sparkpost'
class ApplicationMailer < ActionMailer::Base
default from: "Seal Notification <[email protected]>"
layout 'mailer'
end
signup_mailer.rb
class SignupMailer < ApplicationMailer
def user_signed_up(user)
receiver = user.email
sender = '[email protected]'
title = 'Thanks for registering'
body = 'This is a test body'
sparky = SparkPost::Client.new(SPARKPOST_API_KEY)
sparky.transmission.send_message(receiver,sender,title,body)
end
end
而且我可以成功发送电子邮件。
虽然,由于多种语言和身体风格不同,这绝对不是可扩展的。
现在我需要设置模板以允许非技术人员调整电子邮件模板。
但这里是我坚持和回答下列问题会帮助我极大:
1)如何发送特定电子邮件模板?
2)如何将变量传递给这些模板?
3)如何处理多语言支持?
谢谢。
非常感谢你,特别是你对问题2的回答使它“点击”。 –