Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on Windows使用SMTP库发送电子邮件_Ruby_Smtp_Ruby 2.0 - Fatal编程技术网

Ruby on Windows使用SMTP库发送电子邮件

Ruby on Windows使用SMTP库发送电子邮件,ruby,smtp,ruby-2.0,Ruby,Smtp,Ruby 2.0,我有下面的代码,它在Mac电脑上运行良好,但在windows上失败 require 'net/smtp' opts = {} opts[:server] ||= 'mycompany.com' opts[:from] ||= 'user0@mycompany.com' opts[:from_alias] ||= 'Example' opts[:subject] ||= "You need to see this" opts[:body]

我有下面的代码,它在Mac电脑上运行良好,但在windows上失败

require 'net/smtp'

  opts = {}
  opts[:server]      ||= 'mycompany.com'
  opts[:from]        ||= 'user0@mycompany.com'
  opts[:from_alias]  ||= 'Example'
  opts[:subject]     ||= "You need to see this"
  opts[:body]        ||= "Important stuff!"

  msg = <<END_OF_MESSAGE
From: #{opts[:from_alias]} <#{opts[:from]}>
To: <user0@mycompany.com>
Subject: #{opts[:subject]}

#{opts[:body]}
END_OF_MESSAGE

  Net::SMTP.start(opts[:server]) do |smtp|
    smtp.send_message msg, opts[:from], "user0@mycompany.com"
  end
需要“net/smtp”
opts={}
选项[:server]| |='mycompany.com'
选项[:from]| |='user0@mycompany.com'
选项[:from_alias]| |='Example'
选择[:主题]| |=“您需要查看此内容”
选择[:body]| |=“重要的东西!”

msg=我猜您没有权限在没有身份验证的情况下连接到该服务器。现在,任何健全的SMTP服务器都将有某种身份验证,或者完全安全。您需要研究需要什么样的授权。我建议您与服务器管理员联系。好的。它没有解释为什么它在Mac上工作,因为Mac有一个内置的SMTP客户端库,因为它们是*nix。Windows没有,因为它们是Microsoft。SMTP利用了这一点。这可能是一个起点。net/smtp库仅在Linux或安装了类似于Postfix或Sendmail的邮件客户端的操作系统上工作。我肯定Outlook有一个,或者你可以用Gmail。
Z:\util>ruby test.rb
C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:540:in `initialize': Permission denied - c
onnect(2) (Errno::EACCES)
        from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:540:in `open'
        from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:540:in `tcp_socket'
        from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:550:in `block in do_start'
        from C:/Ruby200/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
        from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:549:in `do_start'
        from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:519:in `start'
        from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:456:in `start'
        from test.rb:19:in `<main>'