既然我的 Heroku SendGrid 集成需要双因素身份验证,我该如何升级?

How do I upgrade my Heroku SendGrid integration now that they require two-factor authentication?

我对 SendGrid 的新变化感到很困惑。我需要更改什么?

我收到一封电子邮件:

We are emailing to inform you that Twilio SendGrid now requires you to authenticate with API Keys, and we require Two-Factor Authentication (2FA) to login to your account as of February 17th, 2021.This requirement is in order to ensure uninterrupted service and improve the security of your account. Our records show that one or more users on your account used basic authentication with username and password for one or more of your SendGrid API requests or SMTP configuration within the last 4 months. If you did not take action, your API and SMTP requests will be rejected starting February 17th, 2021.

我认为我的设置没有使用 API 键,尽管我的环境变量中有一个:

  config.action_mailer.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }

我的 SendGrid 帐户显示 17 日左右发送的邮件明显减少,如电子邮件中所述,但仍有一些 activity,这令人困惑:

我正在使用 sendgrid-ruby (5.3.0) ruby gem

new documentation on SendGrid 似乎说发送 api 密钥作为用户名和密码:

ActionMailer::Base.smtp_settings = {
  :user_name => 'apikey',
  :password => 'your_sendgrid_api_key',
  :domain => 'yourdomain.com',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

但什么是 apikey,它与 your_sendgrid_api_key 有何不同?

此处为 Twilio 开发人员布道师。

当您使用 SendGrid 使用 SMTP 发送电子邮件时,您需要对自己进行身份验证。 SMTP 使用需要用户名和密码的基本身份验证。为了使用 API 密钥作为密码,我们还需要一个用户名。

由于 API 密钥是您实际验证自己所需的全部内容,因此用户名是一种占位符。因此,在示例中,用户名是“apikey”,但实际上应该将其设置为:“apikey”。

然后应将密码设置为您的 API 密钥,您 create in the SendGrid admin console。所以代码应该是这样的:

username = "apikey"
password = ENV["SENDGRID_API_KEY"]

ActionMailer::Base.smtp_settings = {
  :user_name => username,
  :password => password,
  :domain => 'yourdomain.com',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}