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]        ||= "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

带有以下错误消息...

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>'

我需要在 Windows 环境中发送电子邮件吗?

谢谢

4

0 回答 0