使用 Cloud9 IDE 和 Mailgun 在 Devise::RegistrationsController#create 中收到此错误 Net::SMTPSyntaxError

Using Cloud9 IDE and Mailgun getting this error Net::SMTPSyntaxError in Devise::RegistrationsController#create

正在尝试为 RoR4.2 应用程序开发环境设置 Mailgun,但仍然出现上述错误。据我了解,answer 配置开发文件存在问题。

这是我的 config/environments/development.rb:

 config.action_mailer.raise_delivery_errors = true
 config.action_mailer.perform_deliveries = true

 host = 'my_app.c9.io'
 config.action_mailer.default_url_options = { host: host }

 config.action_mailer.delivery_method = :smtp
 config.action_mailer.smtp_settings = {
 address: 'smtp.mailgun.org',
 port: '2525',
 domain:     ENV["MAILGUN_DOMAIN"],
 user_name:  ENV["MAILGUN_USERNAME"],
 password:   ENV["MAILGUN_PASSWORD"],
 authentication: :plain,
 enable_starttls_auto: true,
 }

按照建议 I also checked environment variables in console, they are properly set. I'm using port 2525 as suggested here and here。有什么想法是错误的吗?

尝试使用端口 587 或端口 465。

Cloud9 is currently hosted on Google's infrastructure, and therefore their rules apply to Cloud9 workspaces too. One of their restrictions is regarding SMTP. Basically what this means is:

  • Port 25 is blocked
  • Ports 587, 465, and 2525 can be used
  • Can only use Google Compute Engine partner services, like SendGrid and Google Apps

For details on the matter, please check out this article.

所以我终于得到了答案,无论出于何种原因 Cloud9 不接受这里的环境变量所以我不得不对它们进行硬编码并且不得不使用 "hashrocket" 格式:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true

host = 'my_app.c9.io'
config.action_mailer.default_url_options = { host: host }

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address        => 'smtp.mailgun.org',
:port           => '2525',
:authentication => :plain,
:user_name      => 'postmaster@xxxxxxxxxxxxxxxxx.mailgun.org',
:password       => 'xxxxxxxxxxxxxxxxxxx',
:domain         => 'sandboxxxxxxxxxxxxxxxxxx.mailgun.org',
:enable_starttls_auto => true  
}

如果有人知道如何在 Cloud9 配置开发文件中使用环境变量,请在此处评论。