使用纯 Ruby 发送电子邮件
Sending emails with pure Ruby
我在使用纯 Ruby 发送电子邮件时遇到问题。这是我的脚本的样子:
Mail.defaults do
delivery_method(
:smtp,
address: 'smtp.sendgrid.net',
port: 587,
user_name: 'sendgrid_username',
password: 'sendgrid_password',
authentication: :login,
enable_starttls_auto: false,
openssl_verify_mode: "none"
)
end
Mail.deliver do
from 'Test Email'
to 'user@example.com'
subject 'Here is the image you wanted'
body "Test Email"
end
此脚本引发以下错误:
/Users/mateuszurbanski/.rubies/ruby-2.7.2/lib/ruby/2.7.0/net/smtp.rb:975:in `check_auth_response': 535 Authentication failed: Bad username / password (Net::SMTPAuthenticationError)
我在 Rails 项目上使用我的 Ruby 之一的凭据,它们很好。有什么想法吗?
不要在此配置中使用您的 SendGrid 用户名和密码,而是使用以下内容,
user_name: 'apikey',
password: '<sendgrid_api_key>',
这在为 ActionMailer 定义 smtp 设置时适用于我,因此它在这里也应该适用。
Sendgrid 最近转换为 api 密钥并将拒绝普通身份验证,请参阅 details here。
您仍然有效的旧凭据可能不会被接受。
在 sendgrid 中生成一个新的 api 密钥并用它代替密码。用户名将是 apikey
我在使用纯 Ruby 发送电子邮件时遇到问题。这是我的脚本的样子:
Mail.defaults do
delivery_method(
:smtp,
address: 'smtp.sendgrid.net',
port: 587,
user_name: 'sendgrid_username',
password: 'sendgrid_password',
authentication: :login,
enable_starttls_auto: false,
openssl_verify_mode: "none"
)
end
Mail.deliver do
from 'Test Email'
to 'user@example.com'
subject 'Here is the image you wanted'
body "Test Email"
end
此脚本引发以下错误:
/Users/mateuszurbanski/.rubies/ruby-2.7.2/lib/ruby/2.7.0/net/smtp.rb:975:in `check_auth_response': 535 Authentication failed: Bad username / password (Net::SMTPAuthenticationError)
我在 Rails 项目上使用我的 Ruby 之一的凭据,它们很好。有什么想法吗?
不要在此配置中使用您的 SendGrid 用户名和密码,而是使用以下内容,
user_name: 'apikey',
password: '<sendgrid_api_key>',
这在为 ActionMailer 定义 smtp 设置时适用于我,因此它在这里也应该适用。
Sendgrid 最近转换为 api 密钥并将拒绝普通身份验证,请参阅 details here。 您仍然有效的旧凭据可能不会被接受。
在 sendgrid 中生成一个新的 api 密钥并用它代替密码。用户名将是 apikey