【问题标题】:Sendgrid SMTP templatesSendgrid SMTP 模板
【发布时间】:2016-10-20 05:07:54
【问题描述】:

我一直在阅读 sendgrid-ruby 文档并且遇到了困难。看这个页面,怎么传入模板来使用?

我尝试将各种参数传递给 mail 方法,但没有成功。

https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/ruby.html

我只需要足够的东西就可以开始使用模板了!

【问题讨论】:

    标签: ruby-on-rails sendgrid


    【解决方案1】:

    您想通过 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-'

    【讨论】:

    • 不,我想选择 sendgrid 模板并使用它!目前我所能做的就是发送短信。
    【解决方案2】:

    您可以使用 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 &lt;MailerName&gt;

    并像往常一样设置您的邮件方法和视图。

    http://guides.rubyonrails.org/action_mailer_basics.html

    https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html

    【讨论】:

    • 我特意问的是如何使用 smtp 模板,而不是如何发送电子邮件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 2016-11-10
    • 1970-01-01
    相关资源
    最近更新 更多