【发布时间】:2015-04-24 00:07:13
【问题描述】:
希望你能帮帮我!
我曾经在本地开发,但我在国外,我正在使用 Cloud9 处理一些项目。目前,我很难使用 Action Mailer。
我的 ActionMailer 初始化程序:
ActionMailer::Base.smtp_settings = {
port: '2525',
address: 'smtp.mailgun.org',
user_name: ENV['MAILGUN_SMTP_LOGIN'],
password: ENV['MAILGUN_SMTP_PASSWORD'],
domain: 'app07ad98bdda3b4c469a24228512cffe5c.mailgun.org',
authentication: :plain,
content_type: 'text/html'
}
ActionMailer::Base.delivery_method = :smtp
mailers/gun_mailer.rb
class GunMailer < ActionMailer::Base
default from: "from@example.com"
def welcome_email(user)
@user = user
@url = 'http://example.com/login'
mail(to: @user.email, subject: 'Welcome to My Awesome Site')
end
end
views/gun_mailer/welcome_email.erb
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Welcome to example.com, <%= @user.email %></h1>
<p>
You have successfully signed up to example.com,
your username is: <%= @user.email %>.<br>
</p>
<p>
To login to the site, just follow this link: <%= @url %>.
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
控制台
u = User.first
GunMailer.welcome_email(u).deliver
我已经用 figaro 设置了环境变量,一切似乎都是正确的......但是邮件永远不会发送!我听说 C9 有一些端口被阻塞(587 是其中之一),我尝试使用 2587、2525(如其他海报推荐的那样),但它不起作用!
【问题讨论】:
标签: ruby-on-rails actionmailer cloud9-ide mailgun