Senden Sie E-Mail-von-Ruby-Programm mit TLS

Ich bin versucht, senden Sie eine E-Mail von einem Ruby-Programm. Der smtp-server ist ein Exchange 2007-server erfordert, dass Sie mich anmelden, um die E-Mail senden.

#!/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, '[email protected]', '[email protected]'
end

Wenn ich diesen starte, bekomme ich die folgende Fehlermeldung.

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

Kann ich nicht finden, alles, was in der Ruby-api für Net::SMTP verweisen auf TLS oder STARTTLS Befehl.

BEARBEITEN:
Download von smtp-tls.rb, der code ändert sich nicht viel, aber hier ist was ich habe zu arbeiten.

#!/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', 587, 'test.com', 'username', 'passwd', :login) do |smtp|
    smtp.send_message msgstr, '[email protected]',  ['[email protected]']
end

EDIT: Funktioniert mit ruby 1.8.6

  • Die akzeptierte Antwort ist nicht richtig (oder zumindest nicht mehr).
InformationsquelleAutor Mark | 2009-06-26
Schreibe einen Kommentar