Ruby on Rails 和 Sendinblue 通过 SMTP

Asa*_*uhi 1 ruby-on-rails sendinblue

我想使用 Sendinblue 通过 SMTP 从我的 Ruby on Rails Web 应用程序发送事务电子邮件。我编辑config/environments/production.rb如下:

ActionMailer::Base.smtp_settings = {
  :address => 'smtp-relay.sendinblue.com',
  :port => '587',
  :authentication => :plain,
  :user_name => ???,
  :password => ???,
  :domain => 'fireworks.com',
  :enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)

我应该使用什么 asuser_namepassword?我的帐户的用户名和密码还是我的 SMTP 密钥?另外,我是否需要使用任何 gem,例如sib-api-v3-sdk,或者该 gem 仅适用于使用 Sendinblue API 发送电子邮件?

dan*_*des 10

只需转到您的 SendInBlue 帐户的 API 页面并使用在那里找到的用户名和密码即可。

https://account.sendinblue.com/advanced/api

其他答案建议使用 SMTP 不需要的 gem。您不需要或gems 在普通的 Rails 应用程序中将 SIB 与 ActionMailer 一起使用sendinbluesib-api-v3-sdk

#config/environments/production.rb

config.action_mailer.delivery_method = :smtp

config.action_mailer.smtp_settings = {
  :address        => ENV.fetch('SMTP_HOST', 'smtp-relay.sendinblue.com'),
  :port           => ENV.fetch('SMTP_PORT', '587'),
  :authentication => :plain,
  :user_name      => ENV['SMTP_USERNAME'], #See: https://account.sendinblue.com/advanced/api
  :password       => ENV['SMTP_PASSWORD'], #See: https://account.sendinblue.com/advanced/api
  :enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)