Mark Van De Vyver
2008-Jan-05 17:13 UTC
[Eventmachine-talk] EM:P:SmtpClient and gmail question
Hi Devs, I''ve been trying to use the SmtpClient to send mail to a gmail account from within EM.add_periodic_timer. I can do this using the tlsmail gem using Net:SMTP so I know that the parameters and mail message are formatted OK. EMAIL_ACC = ''uname'' EMAIL_PASSWORD = ''password'' TO_ADDRESS = ''uname at gmail.com'' FROM_ADDRESS = ''uname at gmail.com'' Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) # used with gmail SMTP_SERVER = ''smtp.gmail.com'' SMTP_PORT = 587 SMTP_EHLO = ''localhost.localdomain'' @smtp_hash = {:domain => SMTP_EHLO, :host=>SMTP_SERVER, :port=>SMTP_PORT, :starttls=>true, :auth => {:type => :plain, :username => EMAIL_ACC, :password => EMAIL_PASSWORD}, :from=>FROM_ADDRESS, :to=>[TO_ADDRESS], :verbose=>true} < build ''mail'' here > d = EM::Protocols::SmtpClient.send( @smtp_hash.update(:content => [mail.to_s]) ) d.errback {|e| puts "SMTP client error callback " + e } if d I see (): 220 mx.google.com ESMTP d20sm12963941waa.52 receive_signon 250-mx.google.com at your service, [122.104.188.191] 250-SIZE 28311552 250-8BITMIME 250-STARTTLS 250 ENHANCEDSTATUSCODES receive_ehlo_response 220 2.0.0 Ready to start TLS receive_starttls_response 235 2.7.0 Accepted receive_auth_response 250 2.1.0 OK receive_mail_from_response 250 2.1.5 OK receive_rcpt_to_response 354 Go ahead receive_data_response <repeat several times, i.e periodic timer called> Then I see: SMTP client error callback #<OpenStruct message=[], elapsed_time=63.010303, code=354, start_time=Sun Jan 06 12:10:55 +1100 2008, responder=:receive_message_response> I never get any mail sent to the account..... Any suggestions about what I''ve done wrong? Cheers Mark
Mark Van De Vyver
2008-Jan-05 17:32 UTC
[Eventmachine-talk] EM:P:SmtpClient and gmail question
AAARGH... I built the email using TMail and it seems the message is not properly formatted...> < build ''mail'' here > > > d = EM::Protocols::SmtpClient.send( @smtp_hash.update(:content => > [mail.to_s]) )Should be: d = EM::Protocols::SmtpClient.send( @smtp_hash.update( :content => [(mail.to_s)<<"\r\n.\r\n"] ) ) Anyway I''ve been able to remove one more gem dependency :) Cheers Mark> 250-mx.google.com at your service, [122.104.188.191] > 250-SIZE 28311552 > 250-8BITMIME > 250-STARTTLS > 250 ENHANCEDSTATUSCODES > receive_ehlo_response > 220 2.0.0 Ready to start TLS > receive_starttls_response > 235 2.7.0 Accepted > receive_auth_response > 250 2.1.0 OK > receive_mail_from_response > 250 2.1.5 OK > receive_rcpt_to_response > 354 Go ahead > receive_data_response > > <repeat several times, i.e periodic timer called> > > Then I see: > > SMTP client error callback #<OpenStruct message=[], > elapsed_time=63.010303, code=354, start_time=Sun Jan 06 12:10:55 +1100 > 2008, responder=:receive_message_response> > > I never get any mail sent to the account..... > > Any suggestions about what I''ve done wrong? > > Cheers > Mark >
Francis Cianfrocca
2008-Jan-05 20:59 UTC
[Eventmachine-talk] EM:P:SmtpClient and gmail question
On Jan 5, 2008 8:32 PM, Mark Van De Vyver <mvyver at gmail.com> wrote:> AAARGH... I built the email using TMail and it seems the message is > not properly formatted... > > > < build ''mail'' here > > > > > d = EM::Protocols::SmtpClient.send( @smtp_hash.update(:content => > > [mail.to_s]) ) > > Should be: > > d = EM::Protocols::SmtpClient.send( @smtp_hash.update( :content => > [(mail.to_s)<<"\r\n.\r\n"] ) ) > >You might have an easier time if you use :headers and :body rather than :content. You can avoid formatting it yourself that way. So did you actually get your emails into Gmail this way? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080105/2644f189/attachment.html
Mark Van De Vyver
2008-Jan-06 16:46 UTC
[Eventmachine-talk] EM:P:SmtpClient and gmail question
> > > > You might have an easier time if you use :headers and :body rather than > > :content. You can avoid formatting it yourself that way. > > Yes, but TMail is useful for constructing mail with attachments > (multipart mixed emails), which is my use case. > > > So did you actually get your emails into Gmail this way? > > > > Yes, thanks :)I spoke too soon, seems there is some problem - I get the some emails received a number of times and others not at all. I use some thing like: MYMAILLIST.each do |mail| EM::Protocols::SmtpClient.send( irclog.smtp_hash.update(:content => [(mail.to_s)<<"\r\n.\r\n"]) ) end The STMPClient sends the correct number of emails. I can see all the GMail handshaking occuring simultaneously, so for example I''ll see something like: 220 mx.google.com ESMTP n33sm33522140wag.47 receive_signon 220 mx.google.com ESMTP n40sm33720089wag.34 receive_signon 220 mx.google.com ESMTP n30sm33632931wag.43 receive_signon 220 mx.google.com ESMTP j39sm33748102waf.32 receive_signon 220 mx.google.com ESMTP v25sm33575285wah.14 receive_signon etc. It appears then that the correct number of connections are opened and then the first (some times the first 2-3) email is sent to all the opened connections, and then all the connections are closed. I''d be guessing at what causes this. HTH Mark
Mark Van De Vyver
2008-Jan-06 17:42 UTC
[Eventmachine-talk] EM:P:SmtpClient and gmail question
> I spoke too soon, seems there is some problem - I get the some emails > received a number of times and others not at all. > I use some thing like: > > MYMAILLIST.each do |mail| > EM::Protocols::SmtpClient.send( irclog.smtp_hash.update(:content => > [(mail.to_s)<<"\r\n.\r\n"]) ) > end > > The STMPClient sends the correct number of emails. I can see all the > GMail handshaking occuring simultaneously, so for example I''ll see > something like: > > 220 mx.google.com ESMTP n33sm33522140wag.47 > receive_signon > 220 mx.google.com ESMTP n40sm33720089wag.34 > receive_signon > 220 mx.google.com ESMTP n30sm33632931wag.43 > receive_signon > 220 mx.google.com ESMTP j39sm33748102waf.32 > receive_signon > 220 mx.google.com ESMTP v25sm33575285wah.14 > receive_signon > > etc. > > It appears then that the correct number of connections are opened and > then the first (some times the first 2-3) email is sent to all the > opened connections, and then all the connections are closed. > I''d be guessing at what causes this.I''ve tried moving all the ''messages into an array, say mail_list, then using :content => mail_list, and just calling the StmpClient.send once - nothing gets sent. If I change this so that :content => [mail_list[0]], then I receive that message. So AFAICT :content will work only if it is given an array containing one element? I''ll try making some simple example showing this behavior. HTH> HTH > Mark >
Francis Cianfrocca
2008-Jan-06 18:02 UTC
[Eventmachine-talk] EM:P:SmtpClient and gmail question
On Jan 6, 2008 8:42 PM, Mark Van De Vyver <mvyver at gmail.com> wrote:> > I spoke too soon, seems there is some problem - I get the some emails > > received a number of times and others not at all. > > I use some thing like: > >I''d like to get a repeatable test case. Maybe you could use a newly-created gmail acct so you don''t have to disclose your access credentials. I''m using this SMTP code (both client and server) in some pretty demanding apps now so I''m reasonably confident about it. Given that, I won''t be able to tell if the bug is yours or in EM till I can see a test case. Thanks for helping out on this. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20080106/4a397f13/attachment.html