(Ruby) Getting Net::SMTP working with Gmail...? -
Does anyone have any quality about sending mail through Gmail using Ruby's Net :: SMTP ( And up-to-date) information? I have seen many examples - mostly dating between 2007 and 2008, and none of them works for me. I need more recent examples using the recent 1.8.7 release. I also appreciate that only simple examples were not given in the documentation that never really used anyone.
I am currently receiving an error:
SSL_connect returned = 1 errno = 0 state = SSLv2 / v3 reader hello A: Unknown protocol
I am not very familiar with SSL in relation to the SMTP protocol, so it has lost all on me. Unfortunately Net :: SMTP documentation provides the only basis and one of the various potential OpenSSL :: SSL contexts I do not provide the complete list or I can not try different people.
Anyway, if there is anyone to work with Gmail, any quality information will be most appreciated.
Best.
I really got this job. A quick script was written to test it.
I had received a different error by you (STARTTLS is required), I also found that I had to use port 587 instead of 465.
I found the trick to work in a Rail plugin I found (Agilewebdevelopment.com/plugins/net_smtp_tls_support)
If you 'eval' this file Standards: TLS support adds: SMTP library):
Then run 'net :: SMTP.enable_tls ()'
Everything works fine.
Here is my code:
'rubygems' requires 'net / smtp' eval file. Read ("smtp_tls.rb") net :: SMTP.enable_tls () FROM_EMAIL = "deleted" password = "deleted" TO_EMAIL = "deleted" msgstr = & lt; & Lt; From END_OF_MESSAGE: Your name & lt; # {FROM_EMAIL} & gt; To: My Phone & lt; # {TO_EMAIL} & gt; Subject: Text Message Dates: Saturn, 23 June 2001 16:26:43 + 0900 Message-Id: & lt; Unique.message.id.string@example.com> This is a test message END_OF_MESSAGE Net :: SMTP.start ('smtp.gmail.com', 587, 'gmail.com', FROM_EMAIL, password, plain) do. Smtp | Smtp.send_message msgstr, FROM_EMAIL, TO_EMAIL end
Obviously, I downloaded the above file in the same directory and named it 'smtp_tls.rb'
Hope it helps!
Comments
Post a Comment