It's my first time setting up mails in a rails project. I was told to use SparkPost and to create templates for different languages for several actions.
For simplicity lets say a user_signed_up(user) mail.
Currently I have this setup working:
Gem installed: '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 <noreply@foobar.com>"
layout 'mailer'
end
signup_mailer.rb
class SignupMailer < ApplicationMailer
def user_signed_up(user)
receiver = user.email
sender = 'myself@test.com'
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
And I can successfully send emails.
Although, this is definitely not scaleable due to multi language and body not style-able.
Now I need to setup templates to allow non-technical people to adjust email templates.
But here is where I am stuck and an answer to following questions would help me tremendously:
1) How can I send specific email templates?
2) How do I pass variables to these templates?
3) How do I handle multiple language support?
Thank you.