【问题标题】:Cloud9 and ActionMailer / Mailgun?Cloud9 和 ActionMailer / Mailgun?
【发布时间】: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

ma​​ilers/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


【解决方案1】:

首先,我会确保使用 Rails 控制台在您的 mail.rb 中实际设置了以下变量:

ENV['MAILGUN_SMTP_LOGIN']

ENV['MAILGUN_SMTP_PASSWORD']

其次,您应该通过执行以下操作来验证端口是否未被阻塞:

$ telnet smtp.mailgun.org 2525

$ telnet smtp.mailgun.org 587  

注意:如果您看到类似以下内容,则表示该端口未被阻止:

Trying 104.130.177.23...
Connected to smtp.mailgun.org.
Escape character is '^]'.
220 ak47 ESMTP ready

如果上述端口之一没有被阻塞,那么我会在这里停下来,更新邮件初始化程序以使用未阻塞的端口,然后重新检查您的代码。否则,我会继续阅读。

第三,如果您确定两个端口都被阻止,那么您需要使用 HTTP API,我会在这里阅读文档:

https://documentation.mailgun.com/api-sending.html#sending

使用 Heroku.com 或 DigitalOcean.com 等不同的托管公司。

好吧,我希望以上信息能帮助您解决问题。

【讨论】:

  • 虽然你的解决方案看起来确实够通用,但由于 Cloud9 使用 GCE,我认为这也是相关的:cloud.google.com/compute/docs/tutorials/sending-mail(我不确定 Mailgun 是否是合作伙伴)
  • Mailgun 是一项外部服务,而 GCE 只是另一个类似于 Heroku.com 和 DigitalOcean.com 的托管公司。因此,无论 GCE 是否是 Mailgun 的合作伙伴,Mailgun 都应该按预期工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多