我正试图从我的生产服务器上的控制台发送一些邮件,但它们没有发出.我不明白为什么.我刚刚用sendmail设置了你的标准邮箱.当我给postman 打电话时.我把这个拿回来:

#<TMail::Mail port=#<TMail::StringPort:id=0x3fe1c205dbcc> bodyport=#<TMail::StringPort:id=0x3fe1c2059e00>>

编辑:添加了更多信息:

例如,当新用户注册时,我的控制器中有一行代码,向他们发送"欢迎"邮箱:

 Mailer.deliver_signup(@user, request.host_with_port, params[:user][:password])

这个很好用.我想我应该可以在控制台上做同样的事情

user = User.find(1)
Mailer.deliver_signup(user, "mydomainname.com", "password")

当我这样做的时候,我得到了Tmail::StringPort对象,但是邮件似乎没有被发送出go (我正在try 向自己发送邮箱来测试这个).

我在ubuntu服务器上以防万一.谢谢-麦克斯

推荐答案

对于从Rails控制台发送邮箱,首先我们必须在控制台中执行此设置,以进行action mailer设置.

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.smtp_settings = {
  address: 'smtp.gmail.com', 
  port: 587, 
  domain: 'gmail.com',
  authentication: 'plain', 
  enable_starttls_auto: true, 
  user_name: 'your@gmail.com',
  password: 'yourpassword'
}

之后,如果我们执行邮箱发送代码,它将发送邮箱.

UserMailer.activation_instructions(@user).deliver_now

Ruby-on-rails相关问答推荐

是否可以使用 Turbo 帧更新 Rails 表单输入字段值?

如何在哪里查询 Rails 模型中定义的方法

在 Datatable Ajax 调用中通过 Ajax 更新 div

Ruby 地理定位Ruby /插件

您将如何在 Ruby on Rails 应用程序中使用 rSpec 测试观察者?

如何使用 Capistrano gem 为生产数据库 seeder ?

从 Authlogic 迁移到 Devise

Rails 4,使用 ActiveRecord 的原始查询

rails 方法获取模型的关联名称

不带参数的 request.fullpath

如何在 Rails 1.2.3 中使复选框默认为选中?

连接表的最佳 SQL 索引

form_for 未定义的方法 `user_path'

如何在 RSpec 中包含 Rails 助手

Rails Devise:设置密码重置令牌并重定向用户

如何在 Rails 3 中将多个属性传递给 find_or_create_by?

Rails 3 返回 HTTP 406 Not Acceptable?

如何为 Rails 迁移定义布尔字段

使用连接的 Ruby on Rails ActiveRecord 查询

.erb 、 .rhtml 和 .html.erb 有什么区别?