【发布时间】:2016-10-20 05:07:54
【问题描述】:
我一直在阅读 sendgrid-ruby 文档并且遇到了困难。看这个页面,怎么传入模板来使用?
我尝试将各种参数传递给 mail 方法,但没有成功。
https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/ruby.html
我只需要足够的东西就可以开始使用模板了!
【问题讨论】:
我一直在阅读 sendgrid-ruby 文档并且遇到了困难。看这个页面,怎么传入模板来使用?
我尝试将各种参数传递给 mail 方法,但没有成功。
https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/ruby.html
我只需要足够的东西就可以开始使用模板了!
【问题讨论】:
您想通过 sendgrid 模板传递变量并在 view/html 文件中显示这些变量吗?
class EmailMailer < SampleMailer
def send_data_emails(firstname, lastname)
sendgrid_substitute '-firstname-', firstname
sendgrid_substitute '-lastname-', lastname
end
end
内部视图文件直接使用这些变量来显示值
email_mailer.html.erb
用户名是:'-firstname-' 用户姓氏 id:'-lastname-'
【讨论】:
您可以使用 Ruby on Rails 默认的 ActionMailer 方法通过 SendGrid 发送电子邮件。
在您的 config/environment.rb 中使用您的 SendGrid 设置配置 ActionMailer。
ActionMailer::Base.smtp_settings = {
:user_name => 'your_sendgrid_username',
:password => 'your_sendgrid_password',
:domain => 'yourdomain.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
生成一个新的邮件
rails generate mailer <MailerName>
并像往常一样设置您的邮件方法和视图。
http://guides.rubyonrails.org/action_mailer_basics.html
https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
【讨论】: