[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

strange issue iwth sending smtp with gmail

Junkone

12/23/2007 5:22:00 PM

Hello
When i use this class and execute it, it works fine. i am able to send
email thro gmail. however it does not work if i call this method from
another class. i get a smtp error. dunno what the reasons are. i am
attaching the working file and not working file.


require "action_mailer"
require "smtp_tls"

#ActionMailer::Base.smtp_settings =
#{:address => "smtp.example.com",
# :domain => "example.com"}




class GmailMailer < ActionMailer::Base
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:user_name => "user@gmail.com",
:password => "password"
}
def sendmsg(to, sender, subj, content, strip_ext = true)


#standard ActionMailer message setup
recipients to
from sender
subject subj
#setting the body explicitly means we don't have to provide a
separate template file
body content

##set up the attachment
#attachment :content_type => content_type,
# :body => File.read(file_name),
# :filename => file_name.gsub(/.*\//,'')
end
end
GmailMailer.deliver_sendmsg("anotheremail@hotmail.com","user@gmail.com","hello
this is a test","this is a body")
# The above class works as long as the GmailMailer.deliver is called
with thin the fine.

However the following does not work at all if i call it from another
class
GmailMailer.deliver_sendmsg( "another email
address" ,"user1@gmail.com"," "sometext ","some more text")
I get the following error.
e:/ruby/lib/ruby/site_ruby/1.8/xmlconfigfile.rb:646: warning:
parenthesize argument(s) for future version
e:/ruby/lib/ruby/1.8/net/smtp.rb:680:in `check_response': 555 5.5.2
Syntax error n63sm12043118pyh.5 (Net::SMTPFatalError)
from e:/ruby/lib/ruby/1.8/net/smtp.rb:653:in `getok'
from e:/ruby/lib/ruby/1.8/net/smtp.rb:635:in `rcptto'
from e:/ruby/lib/ruby/1.8/net/smtp.rb:546:in `send0'
from e:/ruby/lib/ruby/1.8/net/smtp.rb:545:in `each'
from e:/ruby/lib/ruby/1.8/net/smtp.rb:545:in `send0'
from e:/ruby/lib/ruby/1.8/net/smtp.rb:472:in `sendmail'
from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
action_mailer/base.rb:567:in `perform_delivery_smtp'
from e:/ruby/lib/ruby/1.8/net/smtp.rb:379:in `start'
from e:/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start'
from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
action_mailer/base.rb:565:in `perform_delivery_smtp'
from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
action_mailer/base.rb:451:in `send'
from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
action_mailer/base.rb:451:in `deliver!'
from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
action_mailer/base.rb:333:in `method_missing'
from E:/TradingTools/CODE/scanForex.rb:46

2 Answers

Junkone

12/23/2007 6:13:00 PM

0

On Dec 23, 12:21 pm, Junkone <junko...@gmail.com> wrote:
> Hello
> When i use this class and execute it, it works fine. i am able to send
> email thro gmail. however it does not work if i call this method from
> another class. i get a smtp error. dunno what the reasons are. i am
> attaching the working file and not working file.
>
> require "action_mailer"
> require "smtp_tls"
>
> #ActionMailer::Base.smtp_settings =
> #{:address => "smtp.example.com",
> # :domain  => "example.com"}
>
> class GmailMailer < ActionMailer::Base
>     ActionMailer::Base.smtp_settings = {
> :address => "smtp.gmail.com",
> :port => 587,
> :authentication => :plain,
> :user_name => "u...@gmail.com",
> :password => "password"
>     }
>   def sendmsg(to, sender, subj, content, strip_ext = true)
>
>     #standard ActionMailer message setup
>     recipients  to
>     from        sender
>     subject     subj
>     #setting the body explicitly means we don't have to provide a
> separate template file
>     body        content
>
>     ##set up the attachment
>     #attachment  :content_type => content_type,
>     #            :body         => File.read(file_name),
>     #            :filename     => file_name.gsub(/.*\//,'')
>   end
> end
> GmailMailer.deliver_sendmsg("anotherem...@hotmail.com","u...@gmail.com","hello
> this is a test","this is a body")
> # The above class works as long as the GmailMailer.deliver is called
> with thin the fine.
>
> However the following does not work at all if i call it from another
> class
> GmailMailer.deliver_sendmsg( "another email
> address" ,"us...@gmail.com"," "sometext ","some more text")
> I get the following error.
> e:/ruby/lib/ruby/site_ruby/1.8/xmlconfigfile.rb:646: warning:
> parenthesize argument(s) for future version
> e:/ruby/lib/ruby/1.8/net/smtp.rb:680:in `check_response': 555 5.5.2
> Syntax error n63sm12043118pyh.5 (Net::SMTPFatalError)
>         from e:/ruby/lib/ruby/1.8/net/smtp.rb:653:in `getok'
>         from e:/ruby/lib/ruby/1.8/net/smtp.rb:635:in `rcptto'
>         from e:/ruby/lib/ruby/1.8/net/smtp.rb:546:in `send0'
>         from e:/ruby/lib/ruby/1.8/net/smtp.rb:545:in `each'
>         from e:/ruby/lib/ruby/1.8/net/smtp.rb:545:in `send0'
>         from e:/ruby/lib/ruby/1.8/net/smtp.rb:472:in `sendmail'
>         from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
> action_mailer/base.rb:567:in `perform_delivery_smtp'
>         from e:/ruby/lib/ruby/1.8/net/smtp.rb:379:in `start'
>         from e:/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start'
>         from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
> action_mailer/base.rb:565:in `perform_delivery_smtp'
>         from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
> action_mailer/base.rb:451:in `send'
>         from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
> action_mailer/base.rb:451:in `deliver!'
>         from e:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.5/lib/
> action_mailer/base.rb:333:in `method_missing'
>         from E:/TradingTools/CODE/scanForex.rb:46

ignorethis post. this actually works. i had a nil email id to send

Thufir Hawat

12/24/2007 5:33:00 AM

0

On Mon, 24 Dec 2007 03:14:58 +0900, Junkone wrote:

> ignorethis post.

Not at all, it was quite interesting and gives food for thought :)



-Thufir