Forum: Ruby How to send the email by Ruby script?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Wesley C. (Guest)
on 2009-06-05 20:51
(Received via mailing list)
Hi, Guys,
I can read my sina.com email by the following code:
require 'net/pop'
Net::POP3.foreach('*pop3.sina.com.cn*', 110,
  'removed_email_address@domain.invalid', 'my_password' ) do |email|
  hdr = email.header
  if hdr =~ /\d+/
    language = hdr.to_s
  else
    language = "INVALID"
  end
  puts language
end

I would like to send email by *smtp.sina.com.cn*, there is code on the
net:

Net::SMTP.start('smtp.sina.com.cn',25) do |smtp|
  smtp.send_message "hello", 'removed_email_address@domain.invalid', 
['removed_email_address@domain.invalid']
end
But I get error message:
*e:/ruby/lib/ruby/1.8/net/smtp.rb:680:in `check_response': 530
Authentication required (Net::SMTPUnknownError)*

So, how can make it I can send the email by the ruby code?

Any suggestion would be quite appreciated.

Thanks.
Wesley C..
Mohit S. (Guest)
on 2009-06-05 20:55
(Received via mailing list)
Wesley C. wrote:
>   end
> Authentication required (Net::SMTPUnknownError)*
>
> So, how can make it I can send the email by the ruby code?
>
> Any suggestion would be quite appreciated.
>

I have a detailed example here:
http://notepad.onghu.com/2007/3/26/sending-email-with-ruby
not sure if it helps.

Cheers,
Mohit.
6/6/2009 | 12:54 AM.
Wesley C. (Guest)
on 2009-06-05 21:10
(Received via mailing list)
Hi, Mohit,
Thank you very much, the code works great!

Thanks.
Wesley C..
Wesley C. (Guest)
on 2009-06-05 21:34
(Received via mailing list)
But do you know how to send the email with an attachment?

Thanks.
Wesley C..
Mohit S. (Guest)
on 2009-06-05 22:10
(Received via mailing list)
Wesley C. wrote:
> But do you know how to send the email with an attachment?
>
> Thanks.
> Wesley C..
>

I haven't needed to, but a Google search should find you quite a few
hits.

Cheers,
Mohit.
6/6/2009 | 2:07 AM.
This topic is locked and can not be replied to.