我想在我的Rails应用中发送电子邮件,但我不知道为什么电子邮件没有发送到电子邮件目的地,而在我的日志中发送电子邮件。这是environment/development.rb
中的电子邮件发件人设置:
MyApp::Application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => 'my_username',
:password => 'my_pass',
:authentication => 'plain',
:enable_starttls_auto => true }
end
这是我的UserMailer.rb
:
class UserMailer < ActionMailer::Base
def checkout(admin_email, email, ids, store_name)
@email = email
@seller = admin_email
@store_name = store_name
@orders = []
@store = Store.where("name = ?", store_name).first
ids.each do |f|
@orders << Order.find(f)
end
mail(:to => "<#{email}>", :from => "<#{admin_email}>", :subject => "checkout confirmation")
end
end
以及我的控制器中用于发送电子邮件的代码:
UserMailer.checkout(admin_email, email, ids, store.name).deliver
为什么这封电子邮件似乎已发送,(根据日志)但未发送给收件人?
答案 0 :(得分:-1)
如果您使用的是Gmail,请确保您的用户名字段实际为:username@gmail.com 我遇到了类似的问题,一旦我更改了用户名
就行了