我正在开发一个应用程序在Rails 4上。当用户使用devise gem注册时,该人可以收到一封电子邮件。但对于successful checkout
这样的情况,尽管控制台中有InvoiceMailer#checkout: processed outbound mail in 207.2ms
和Sent mail to admin@example.com (4134.8ms)
消息,但用户仍未收到任何电子邮件。
以下是我的代码: 控制器
def success_checkout
token = params[:token]
payer_id = params[:PayerID]
@invoice = Invoice.find_by_token(token)
request = Paypal::Express::Request.new(
:username => PAYPAL_CONFIG[:username],
:password => PAYPAL_CONFIG[:password],
:signature => PAYPAL_CONFIG[:signature]
)
payment_request = Paypal::Payment::Request.new(
:currency_code => @invoice.currency,
:description => "New payment for travel booking",
:quantity => 1,
:amount => @invoice.amount_cents.to_i / 100
)
response = request.checkout!(
params[:token],
params[:PayerID],
payment_request
)
gon.is_display_currency_exchange = false
@currency_symbol = get_all_currency_symbols[@invoice.currency]
if response.ack == 'Success'
@invoice.update_attributes(:payer_id => payer_id, :status => "paid")
if @invoice.is_reward_credit
current_user.reward_credit -= 5
current_user.save
end
(1..3).each do |i|
InvoiceMailer.checkout(@invoice, i).deliver_now
end
flash[:success] = "Checkouted successfully."
else
flash[:danger] = "There is an error while processing the payment."
end
end
InvoiceMailer
class InvoiceMailer < ActionMailer::Base
default from: "MySite <support@example.com>"
include ApplicationHelper
def checkout(invoice,i)
@invoice = invoice
@currency_symbols = get_all_currency_symbols
logger.info "{event=CHECKOUT_RECEIPT status=successful store=#{invoice.contact_detail.email}}"
mail(:to => invoice.contact_detail.email, :subject => "Receipt of example")
end
end
我的development.rb
邮件程序配置
#For mailer configs
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { host: 'www.example.com'};
config.action_mailer.smtp_settings = {
:address => 'email-smtp.us-west-2.amazonaws.com',
:port => 587,
:authentication => :plain,
:user_name => 'KEY',
:password => 'SECRET',
:enable_starttls_auto => true
}
记录器消息会在控制台中以{event=CHECKOUT_RECEIPT status=successful store=user@example.com}
打印出来。但是没有收到邮件。感谢!!!