0

因此,当有人填写与我们联系的表格时,我尝试发送电子邮件,但是当我添加时:

export GMAIL_USERNAME="myapp@domain.com"
export GMAIL_PASSWORD="secret"

对我

~/.bashrc

文件,并将我的development.rb文件设置如下,我的应用程序返回一个

Net::SMTPAuthenticationError 530-5.5.1 Authentication Required

但是当我用它的实际值替换ENV["GMAIL_USERNAME"]& ENV["GMAIL_PASSWORD"]indevelopment.rb时,我发送电子邮件就没有问题了。添加到~./bashrc文件中是否不能确保ENV["GMAIL_USERNAME"]&ENV["GMAIL_PASSWORD"]被真实值替换?有人可以帮忙吗?

我已经尝试了谷歌的说明ENV["GMAIL_USERNAME"],但是当我使用&时它不起作用ENV["GMAIL_PASSWORD"](而不是它们的实际值)。

这是我development.rb文件的相关部分:

  # Raise error if the mailer can't send
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.perform_deliveries = true
  config.action_mailer.default :charset => "utf-8"

  # Use SMTP to send mail
  config.action_mailer.delivery_method = :smtp

  # Use awesomeness@novulty.com (google app) to send smtp mail
  config.action_mailer.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :domain               => "domain", # real domain name in my file
    :user_name            => ENV["GMAIL_USERNAME"],
    :password             => ENV["GMAIL_PASSWORD"],
    :authentication       => :plain,
    :enable_starttls_auto => true
  }

  # Specify what domain to use for mailer URLs
  config.action_mailer.default_url_options = {
    host: "localhost:3000"
  }

谢谢!

更新

我的 .bashrc 文件如下所示:

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export GMAIL_USERNAME=***********
export GMAIL_PASSWORD=***********

但是当我打开终端并输入env时,GMAIL_*变量没有被列出,但 rvm 被添加到PATH. 这让我很困扰……哈哈。

再次感谢!

4

2 回答 2

1

实际上,事实证明我的 shell 没有读取.bashrc文件,所以我必须包含source ~/.bashrc~/.bash_profile文件中。之后一切正常。感谢@David 的帮助!

于 2012-10-09T07:28:20.457 回答
1

看起来你试图在 Bash 中编写一些 ruby​​:不允许。设置环境变量的正确语法是:

export GMAIL_USERNAME=myapp@domain.com

您可以运行env以验证它是否已正确设置。

于 2012-10-09T05:06:20.093 回答