我正在尝试从
Ruby程序发送电子邮件. smtp服务器是Exchange 2007服务器,需要我登录才能发送电子邮件.
#!/usr/bin/ruby require 'rubygems' require 'net/smtp' msgstr = "Test email." smtp = Net::SMTP.start('smtp.server.com',587,'mail.server.com','username','password',:login) do |smtp| smtp.send_message msgstr,'from@server.com','to@server.com' end
当我运行这个时,我得到以下错误.
/usr/lib/ruby/1.8/net/smtp.rb:948:in `check_auth_continue': 530 5.7.0 Must issue a STARTTLS command first (Net::SMTPAuthenticationError) from /usr/lib/ruby/1.8/net/smtp.rb:740:in `auth_login' from /usr/lib/ruby/1.8/net/smtp.rb:921:in `critical' from /usr/lib/ruby/1.8/net/smtp.rb:739:in `auth_login' from /usr/lib/ruby/1.8/net/smtp.rb:725:in `send' from /usr/lib/ruby/1.8/net/smtp.rb:725:in `authenticate' from /usr/lib/ruby/1.8/net/smtp.rb:566:in `do_start' from /usr/lib/ruby/1.8/net/smtp.rb:525:in `start' from /usr/lib/ruby/1.8/net/smtp.rb:463:in `start'
我在Ruby api for Net::SMTP引用TLS或STARTTLS命令中找不到任何内容.
编辑:
下载smtp-tls.rb,代码没有太大变化,但这是我的工作.
#!/usr/bin/ruby require 'rubygems' require 'net/smtp' require 'smtp-tls' msgstr = <<MESSAGE_END From: me <me@test.com> To: you <you@test.com> Subject: e-mail test body of email MESSAGE_END smtp = Net::SMTP.start('smtp.test.com','test.com','passwd','me@test.com',['you@test.com'] end
编辑:与ruby 1.8.6一起使用