我已经将ActionMailer完美地工作了一年半,现在它只是偶尔通过Gmail发送电子邮件。有时,有时并非总是如此。我在heroku日志上收到发送确认,但是没有以gmail发送电子邮件的记录。
有人遇到过这样的行为吗?
config.action_mailer.default_url_options = { host: ENV.fetch('HOST') }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default charset: 'utf-8'
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: ENV['GMAIL_DOMAIN'],
authentication: 'plain',
enable_starttls_auto: true,
user_name: ENV['GMAIL_USERNAME'],
password: ENV['GMAIL_PASSWORD']
}
-
class ApplicationMailer < ActionMailer::Base
default from: ENV['GMAIL_USERNAME']
layout 'mailer'
end
-
class ContactUsMailer < ApplicationMailer
def send_email(params)
@name = params[:name]
@email = params[:email_address]
@message = params[:message]
mail(to: EmailAddress.contact_us.email_address, subject: "Contact us email from #{@name}")
end
end
日志:
Started POST "/contact_us" for 73.55.199.157 at 2018-10-23 21:52:50 +0000
Processing by ContactUsController#create as JS
Parameters: {"contact_us"=>{"name"=>"test email", "email_address"=>"test@test.com", "message"=>"testing email "}}
Rendering contact_us_mailer/send_email.html.slim within layouts/mailer
Rendered contact_us_mailer/send_email.html.slim within layouts/mailer (0.3ms)
ContactUsMailer#send_email: processed outbound mail in 6.6ms
电子邮件帐户主要用于发送购买确认。有三个邮递员使用相同的电子邮件帐户,每个邮递员的行为方式也相同。
编辑:这似乎是Gmail上退回电子邮件的阈值达到阈值的问题。通过使用新的Gmail帐户暂时解决了该问题,但需要使用此帐户才能切换到更永久的解决方案。