简体   繁体   English

Sendgrid SMTP模板

[英]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.

相关问题 通过Rails电子邮件元数据发送Sendgrid SMTP - Sendgrid SMTP via Rails email metadata Rails ActionMailer 使用 API 方法而不是 SMTP - SendGrid - Rails ActionMailer using API method instead of SMTP - SendGrid Sendgrid返回请求的SMTP-AUTH,但缺少用户名 - Sendgrid returns SMTP-AUTH requested but missing user name 如果没有SendGrid附加组件,我们可以在heroku中使用smtp吗? - Can we use smtp with heroku without the SendGrid add-on? 特殊字符的编码不适用于 sendgrid 模板的电子邮件主题 - Encoding for special characters not working in email subject for sendgrid templates Rails Mailer中的“默认来源”值错误导致Heroku中使用SendGrid的SMTP错误 - Wrong “Default From” value in Rails Mailer leads to SMTP error on Heroku with SendGrid 获取NoMethodError(#的未定义方法“合并” - Getting NoMethodError (undefined method `merge' for #<RailsConfig::Options address=“smtp.sendgrid.net”, port=587 为什么在开发模式下使用SendGrid SMTP Relay从Heroku Rails应用程序发送的收件箱中没有收到任何电子邮件? - Why can't I see any emails in my inbox sent from my Heroku Rails app using SendGrid SMTP Relay in development mode? 适用于ActiveAdmin的Sendgrid - Sendgrid for ActiveAdmin Sendgrid模板 - Sendgrid template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM