[关闭]
@openxy 2016-03-14T20:53:56.000000Z 字数 1590 阅读 1808

rails shell and email

未分类


ruby shell

  1. 基础知识 http://segmentfault.com/a/1190000000368191

  2. 较复杂情况 http://zetcode.com/lang/rubytutorial/io/

示例

  1. ret = Kernel.open("| php ./php/export.php",'w+b') do |f|
  2. f.write(json)
  3. end

rails send email

代码 

首先使用 rails g mailer XMailer 生成相关的代码,可参考上面链接中的说明;
>下面的代码主要为smtp配置及调试相关

  1. config.action_mailer.delivery_method = :smtp
  2. config.action_mailer.perform_deliveries = true
  3. config.action_mailer.raise_delivery_errors = true
  1. config.action_mailer.delivery_method = :letter_opener
  1. gem "letter_opener"
  1. ActionMailer::Base.smtp_settings = {
  2. :address => "smtp.qq.com",
  3. :port => 25,
  4. :domain => "x.com",
  5. :user_name => "xxx@qq.com",
  6. :password => "xxxx",
  7. :authentication => "plain",
  8. :enable_starttls_auto => true,
  9. # https://github.com/rails/rails/issues/892
  10. # :openssl_verify_mode => 'none'
  11. }
  12. ActionMailer::Base.default_url_options[:host] = "localhost:3000"
  13. # use letter_opener gem for devlopment
  14. require "development_mail_interceptor"
  15. Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
  1. class DevelopmentMailInterceptor
  2. def self.delivering_email(message)
  3. message.subject = "to:#{message.to}: #{message.subject}"
  4. #message.to = Rails.env.development? ? "xxx@qq.com" : "xxx2@qq.com"
  5. message.to = "xxx@qq.com"
  6. message.cc = "xxx@qq.com"
  7. end
  8. end

关于email的调试

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注