[英]Sendgrid SMTP templates
I've been reading over the sendgrid-ruby documentation and having a hard time. 我一直在阅读sendgrid-ruby文档,并且很辛苦。 Looking at this page, how do I pass in a template to use?
在此页面上,我如何传递要使用的模板?
I've tried passing various parameters into the mail method, but it's not been working. 我尝试过将各种参数传递到mail方法中,但是没有用。
https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/ruby.html https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/ruby.html
I just need enough to get started with templating! 我只需要足够的资源即可开始使用模板!
Do you want to pass variables via sendgrid template and display those variables inside view/html file? 您是否要通过sendgrid模板传递变量并在view / html文件中显示这些变量?
class EmailMailer < SampleMailer
def send_data_emails(firstname, lastname)
sendgrid_substitute '-firstname-', firstname
sendgrid_substitute '-lastname-', lastname
end
end
inside view file directly use these variables to display values 内部视图文件直接使用这些变量来显示值
email_mailer.html.erb email_mailer.html.erb
User First Name is: '-firstname-' User Last Name id: '-lastname-'
用户的名字是:“-firstname-”用户的名字ID:“-lastname-”
You can use Ruby on Rails default ActionMailer methods for sending email through SendGrid. 您可以使用Ruby on Rails的默认ActionMailer方法来通过SendGrid发送电子邮件。
In your config/environment.rb
configure ActionMailer with your SendGrid settings. 在
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
}
Generate a new mailer with 产生一个新的邮件
rails generate mailer <MailerName>
and setup your mailer methods and views as usual. 并照常设置您的邮寄方法和视图。
http://guides.rubyonrails.org/action_mailer_basics.html
http://guides.rubyonrails.org/action_mailer_basics.html
https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.