[英]How do I send emails using Sendgrids API to send emails with rails 4? I can seem to put all the pieces together
我想從谷歌雲平台實例發送帶有sendgrids API的電子郵件。 他們有一個關於如何執行此操作的簡短教程,但它有電子郵件消息,來自發送者,發送者以及app.rb
其他信息,這不是在rails應用程序中發送消息的正常方式。
我查看了sendgrid ruby文檔 ,他們也沒有很好的信息。 在一個地方的所有信息,他們不說明要放入哪些文件,甚至提及要使用的任何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::Mail
就像我在幾個地方看到的那樣? 我是新手在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
}
使用Figaro gem: https : //github.com/laserlemon/figaro它將為您生成一個application.yml文件,您可以在其中存儲sendgrid_username和sendgrid_password。
你有沒有生成郵件? 例如,生成郵件程序user_notifier,您可以在其中定義默認的電子郵件,以及一些類似這樣的方法:
[R
# send a signup email to the user, pass in the user object that contains the
user email address
default :from => 'hello@yourdomain.com'
def send_signup_email(user)
@user = user
mail( :to => @user.email,
:subject => 'Thanks for signing up!'
)
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.