使用Gmail发送电子邮件有效但Mailapp却没有。这是正在发生的事情:
GMAIL SETTINGS:正在运作!!!
appname / config / initializers / setup_mail.rb RailsCast
ActionMailer::Base.smtp_settings ={
:address => "smtp.gmail.com",
:port => 587,
:user_name => "gmailusername",
:password => "gmailpassword",
:authentication => "plain",
:domain => "http://localhost:3000",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
应用程序名称/应用/邮寄者/ newsletter_mailer.rb
class NewsletterMailer < ActionMailer::Base
default from: "myemail@gmail.com" #for gmai
def registration_confirmation(newsletter)
@newsletter = newsletter
mail(:to => (newsletter.email), :Subject => "Thank you for signing up with us")
end
end
应用程序名称/应用/控制器/ newsletters_controller.rb
def create
@newsletter = Newsletter.new(params[:newsletter])
respond_to do |format|
if @newsletter.save
NewsletterMailer.registration_confirmation(@newsletter).deliver
format.html { redirect_to @newsletter, notice: 'Newsletter was successfully created.' }
format.json { render json: @newsletter, status: :created, location: @newsletter }
else
format.html { render action: "new" }
format.json { render json: @newsletter.errors, status: :unprocessable_entity }
end
end
end
应用程序名称/应用/视图/ newsletter_mailer / registration_confirmation.html.erb
Hello <%= @newsletter.name %>,<br>
Thank you for signing up!<br><br>
Thank you.
MAILGUN SETTINGS:不工作?
应用程序名称/配置/初始化/为setup_mail.rb
ActionMailer::Base.smtp_settings ={
:address => "smtp.mailgun.org",
:port => 587,
:user_name => "postmaster@sandbox481.mailgun.org",
:password => "mailgunpassword",
:authentication => :plain,
:domain => "sandbox481.mailgun.org",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000" #tried sandbox481.mailgun.org too without any luck.
应用程序名称/应用/邮寄者/ newsletter_mailer.rb
class NewsletterMailer < ActionMailer::Base
default from: "postmaster@sandbox481.mailgun.org"
def registration_confirmation(newsletter)
@newsletter = newsletter
mail(:to => (newsletter.email), :Subject => "Thank you for signing up with us")
end
end
应用程序名称/应用/控制器/ newsletters_controller.rb
def create
@newsletter = Newsletter.new(params[:newsletter])
respond_to do |format|
if @newsletter.save
NewsletterMailer.registration_confirmation(@newsletter).deliver
format.html { redirect_to @newsletter, notice: 'Newsletter was successfully created.' }
format.json { render json: @newsletter, status: :created, location: @newsletter }
else
format.html { render action: "new" }
format.json { render json: @newsletter.errors, status: :unprocessable_entity }
end
end
end
应用程序名称/应用/视图/ newsletter_mailer / registration_confirmation.html.erb
Hello <%= @newsletter.name %>,<br>
Thank you for signing up!<br><br>
Thank you.
这是我从Log(终端)
获得的Rendered newsletter_mailer/registration_confirmation.html.erb (0.1ms)
Sent mail to myemail@gmail.com (30005ms)
Date: Fri, 15 Nov 2013 15:47:19 -0600
From: postmaster@sandbox481.mailgun.org
To: myemail@gmail.com
Message-ID: <528696672b8de_be625a2854253423@ubuntu-VirtualBox.mail>
Subject: Registration confirmation
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Hello P Dahal,<br>
Thank you for signing up!<br><br>
Thank you.
Redirected to http://localhost:3000/newsletters/10
Completed 302 Found in 30028ms (ActiveRecord: 14.2ms)
但我的收件箱中没有收到该邮件(myemail@gmail.com)。