加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何使用Sendgrids API发送电子邮件以使用rail

发布时间:2020-12-17 02:09:16 所属栏目:百科 来源:网络整理
导读:我想从谷歌云平台实例发送带有sendgrids API的电子邮件.他们有一个 short tutorial on how to do this,但它有电子邮件消息,来自发送者,发送者和其他信息都在app.rb中,这不是在rails应用程序中发送消息的正常方式. 我看了sendgrid ruby docs,他们也没有很好的
我想从谷歌云平台实例发送带有sendgrids API的电子邮件.他们有一个 short tutorial on how to do this,但它有电子邮件消息,来自发送者,发送者和其他信息都在app.rb中,这不是在rails应用程序中发送消息的正常方式.

我看了sendgrid ruby docs,他们也没有很好的信息.在一个地方的所有信息,他们不说明要放入哪些文件,甚至提及要使用的任何smtp设置.

这是我到目前为止所拥有的

development.rb

config.action_mailer.delivery_method = :smtp
# SMTP settings
config.action_mailer.smtp_settings = {
 :address              => "smtp.sendgrid.net",:port                 => 465,:domain               => "mydomain.com",:user_name            => ENV['sendgrid_username'],:password             => ENV['sendgrid_password'],:authentication       => :plain,:ssl                  => true,:enable_starttls_auto => true
}

的Gemfile

gem "sendgrid-ruby"

电子邮件视图在app / views中,邮件程序方法在app / mailer中与普通rails 4应用程序设置相同.

所以我想这是我的主要问题:

>我在哪里调用包含sendgrid api密钥的环境变量?
>我在哪里告诉Action Mailer使用sendgrid或SendGrid :: Mail,就像我在几个地方看到的那样?
>我甚至需要sendgrid宝石吗?
>使用sendgrid通过SSL发送smtp设置是否正确?

我是新手在rails应用程序中发送这样的电子邮件,非常感谢帮助.

解决方法

将apikey作为名称,将实际的apikey作为密码:

config.action_mailer.smtp_settings = {
  address:        "smtp.sendgrid.net",port:           587,domain:         "yourwebsite.com",authentication: :plain,user_name:      'apikey',password:       Rails.application.secrets.sendgrid_api_key
}

Source

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读