J'essaie d'envoyer un e-mail à partir d'un programme Ruby. Le serveur smtp est un serveur Exchange 2007 qui nécessite que je me connecte pour envoyer l'email.Envoyer un e-mail à partir du programme Ruby avec TLS
#!/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
Lorsque j'exécute ceci, j'obtiens l'erreur suivante.
/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'
Je ne peux pas trouver quoi que ce soit dans les Ruby api for Net::SMTP faisant référence TLS ou une commande STARTTLS.
EDIT: Télécharger smtp-tls.rb, le code ne change pas beaucoup mais voici ce que je dois travailler.
#!/usr/bin/ruby
require 'rubygems'
require 'net/smtp'
require 'smtp-tls'
msgstr = <<MESSAGE_END
From: me <[email protected]>
To: you <[email protected]>
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: Fonctionne avec Ruby 1.8.6
La réponse acceptée n'est pas correcte (ou du moins, n'est plus). –