0

我想使用 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
}

我应该使用什么作为user_nameand password?我的帐户的用户名和密码或我的 SMTP 密钥?另外,我是否需要使用任何 gem,比如sib-api-v3-sdk,或者这个 gem 仅对使用 Sendinblue API 发送电子邮件有用?

4

3 回答 3

2

这就是将 SendInBlue 与 ActionMailer 一起使用所需的全部内容。其他答案建议使用 SMTP 不需要的 gem。在普通的 Rails 应用程序中,您不需要或gemssendinblue即可将 SIB 与 ActionMailer 一起使用。sib-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
}
于 2021-11-11T16:27:46.247 回答
1

将此添加到您的 gemfile

gem 'sib-api-v3-sdk'

将此添加到 config/environments/production.rb

  config.action_mailer.default_url_options = { host: "your_domain.com", port: 587 }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp-relay.sendinblue.com",
    :port => 587,
    :user_name => ENV['SEND_IN_BLUE_USERNAME'],
    :password => ENV['SEND_IN_BLUE_PASSWORD'],
    :authentication => 'login',
    :enable_starttls_auto => true
  }

将此添加到 config/initializers/send_in_blue.rb

SibApiV3Sdk.configure do |config|
  config.api_key['api-key'] = ENV["SEND_IN_BLUE_API_KEY"]
end

确保您的环境变量是正确的。它在生产中对我有用。

于 2020-12-03T02:51:39.497 回答
0

可以添加gem 'sendinblue'官方Sendinblue提供的 API V2 Ruby GEM

为了发送电子邮件,您需要更改 smtp 设置config/environments/*.rb(以适用者为准)

Rails.application.configure do
  #append this settings
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => ‘smtp-relay.sendinblue.com’,
    :port => 587,
    :user_name => ‘YOUR_SENDINBLUE_EMAIL’,
    :password => ‘YOUR_SENDINBLUE_PASSWORD’,
    :authentication => ‘login’,
    :enable_starttls_auto => true
  }
end

在您的设置帐户中更改 STMP 和 API

STMP SERVER --> smtp-relay.sendinblue.com
port --> 587
于 2020-01-19T18:01:59.987 回答