# How can send email message using ruby?

**URL:** <https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421>\
**Category:** ruby-talk\
**Created:** [16 October 2007 10:30 UTC](https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421 "2007-10-16T10:30:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arul\_hari](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Arul\_hari](https://rubytalk.org/u/Arul_hari)\
**Post date:** [16 October 2007 10:30 UTC](https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421/1 "2007-10-16T10:30:37Z")

</div>

Dear friends,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Can anybody try this question.  
Is there any way to send the message our own email,for  
example.yahoo-id,rediff-id.  
how can we send the message using ruby [program.Is](http://program.Is) there any classes.  
If any one try means please give the solution to me.

Thank you

by  
vellingiri.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Mohit\_Sindhwani1](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mohit\_Sindhwani1](https://rubytalk.org/u/Mohit_Sindhwani1)\
**Post date:** [16 October 2007 10:35 UTC](https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421/2 "2007-10-16T10:35:08Z")

</div>

Vellingiri Arul wrote:

> Dear friends,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Can anybody try this question.  
> Is there any way to send the message our own email,for  
> example.yahoo-id,rediff-id.  
> how can we send the message using ruby program.Is there any classes.  
> If any one try means please give the solution to me.
> 
> Thank you
> 
> by  
> vellingiri.  
> &nbsp;&nbsp;  
> You will most likely need to use SMTP. You can have a look at the code that you'll find online when you search for send email with Ruby. Or you can take a look at: [http://notepad.onghu.com/2007/3/26/sending-email-with-ruby](http://notepad.onghu.com/2007/3/26/sending-email-with-ruby)

You will just need to set your "From" address in the email to be whatever ID that you want it to be. I'm not sure, though, if Yahoo! mail will block email from a Yahoo! ID that has not originated from a yahoo server. You'll just have to try.

For me, I use SMTP and it works fine 🙂

Cheers,  
Mohit.  
10/16/2007 | 6:34 PM.

---

<div class="post-metadata">

**Author:** ![Jesus\_Gabriel\_y\_Gala](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Jesus\_Gabriel\_y\_Gala](https://rubytalk.org/u/Jesus_Gabriel_y_Gala)\
**Post date:** [16 October 2007 11:08 UTC](https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421/3 "2007-10-16T11:08:07Z")

</div>

This is how I do it, with ActionMailer is extra simple !!!:

require 'action\_mailer'

ActionMailer::Base.smtp\_settings = { :address =\> 'your\_smtp\_address',  
:domain =\> 'a\_valid\_domain\_for\_the\_smtp\_server'}

class SimpleMail \< ActionMailer::Base  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def simple (from, to, subject, body)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from from  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recipients to  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subject subject  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;body body  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
end

SimpleMail.deliver\_simple('from@from.com', 'to@to.com', 'test', 'this  
is a test')

Is that simple. If you need any other thing like attachments, you can  
look at the documentation for ActionMailer or ask here.

Good luck,

Jesus.

> **···**
>
> On 10/16/07, Mohit Sindhwani \<mo\_mail@onghu.com\> wrote:
> 
> > Vellingiri Arul wrote:  
> > \> Dear friends,  
> > \> Can anybody try this question.  
> > \> Is there any way to send the message our own email,for  
> > \> example.yahoo-id,rediff-id.  
> > \> how can we send the message using ruby program.Is there any classes.  
> > \> If any one try means please give the solution to me.
> 
> > For me, I use SMTP and it works fine 🙂

---

<div class="post-metadata">

**Author:** ![Arul\_hari](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Arul\_hari](https://rubytalk.org/u/Arul_hari)\
**Post date:** [16 October 2007 11:59 UTC](https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421/4 "2007-10-16T11:59:53Z")

</div>

Mohit Sindhwani wrote:

> Vellingiri Arul wrote:
> 
> > vellingiri.  
> > &nbsp;&nbsp;  
> > You will most likely need to use SMTP. You can have a look at the code  
> > that you'll find online when you search for send email with Ruby. Or  
> > you can take a look at:  
> > [http://notepad.onghu.com/2007/3/26/sending-email-with-ruby](http://notepad.onghu.com/2007/3/26/sending-email-with-ruby)
> 
> You will just need to set your "From" address in the email to be  
> whatever ID that you want it to be. I'm not sure, though, if Yahoo!  
> mail will block email from a Yahoo! ID that has not originated from a  
> yahoo server. You'll just have to try.
> 
> For me, I use SMTP and it works fine 🙂
> 
> Cheers,  
> Mohit.  
> 10/16/2007 | 6:34 PM.

Hai friend,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I don't understand what they are saying.  
They have mentioned the server ,subject and different types of formats.  
Please give me the proper example for me.  
This is my humble request.kindly help me.

by  
vellingiri

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Mohit\_Sindhwani1](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mohit\_Sindhwani1](https://rubytalk.org/u/Mohit_Sindhwani1)\
**Post date:** [17 October 2007 06:24 UTC](https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421/5 "2007-10-17T06:24:29Z")

</div>

Vellingiri Arul wrote:

> Mohit Sindhwani wrote:  
> &nbsp;&nbsp;
> 
> > Vellingiri Arul wrote:  
> > &nbsp;&nbsp;&nbsp;&nbsp;
> > 
> > > vellingiri.  
> > > &nbsp;&nbsp;
> > 
> > You will most likely need to use SMTP. You can have a look at the code  
> > that you'll find online when you search for send email with Ruby. Or  
> > you can take a look at:  
> > [http://notepad.onghu.com/2007/3/26/sending-email-with-ruby](http://notepad.onghu.com/2007/3/26/sending-email-with-ruby)
> > 
> > You will just need to set your "From" address in the email to be  
> > whatever ID that you want it to be. I'm not sure, though, if Yahoo!  
> > mail will block email from a Yahoo! ID that has not originated from a  
> > yahoo server. You'll just have to try.
> > 
> > For me, I use SMTP and it works fine 🙂
> > 
> > Cheers,  
> > Mohit.  
> > 10/16/2007 | 6:34 PM.  
> > &nbsp;&nbsp;&nbsp;&nbsp;  
> > Hai friend,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I don't understand what they are saying.  
> > They have mentioned the server ,subject and different types of formats.  
> > Please give me the proper example for me.  
> > This is my humble request.kindly help me.
> 
> by  
> vellingiri  
> &nbsp;&nbsp;

Hi, please explain your question more clearly. I think you asked a similar question in a separate thread (relating to POP) and I don't know what you require.

It appears that your concepts on email are not very clear. Please do read about SMTP and IMAP servers for sending email.

To the best of my knowledge, Yahoo does not let you use/ access their SMTP servers for free. You will need to sign for some service. To the best of my knowledge, there's no easy and reliable way to use Yahoo webmail from a script although some people have tried that. If you sign up for a service from Yahoo, then you will need to use code similar to the one I gave (or the ActionMailer example that was posted in response to mine) - either way, you need to spend some time understanding how email works and what the protocols mean.

Best Regards  
Mohit.

---

<div class="post-metadata">

**Author:** ![Arul\_hari](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Arul\_hari](https://rubytalk.org/u/Arul_hari)\
**Post date:** [17 October 2007 06:55 UTC](https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421/6 "2007-10-17T06:55:29Z")

</div>

Mohit Sindhwani wrote:

> Vellingiri Arul wrote:
> 
> > > [http://notepad.onghu.com/2007/3/26/sending-email-with-ruby](http://notepad.onghu.com/2007/3/26/sending-email-with-ruby)  
> > > 10/16/2007 | 6:34 PM.  
> > > &nbsp;&nbsp;
> 
> Hi, please explain your question more clearly. I think you asked a  
> similar question in a separate thread (relating to POP) and I don't know  
> what you require.
> 
> It appears that your concepts on email are not very clear. Please do  
> read about SMTP and IMAP servers for sending email.
> 
> To the best of my knowledge, Yahoo does not let you use/ access their  
> SMTP servers for free. You will need to sign for some service. To the  
> best of my knowledge, there's no easy and reliable way to use Yahoo  
> webmail from a script although some people have tried that. If you sign  
> up for a service from Yahoo, then you will need to use code similar to  
> the one I gave (or the ActionMailer example that was posted in response  
> to mine) - either way, you need to spend some time understanding how  
> email works and what the protocols mean.
> 
> Best Regards  
> Mohit.

Hi Mohit,  
Your program Error:  
&nbsp;&nbsp;&nbsp;smtp.rb:1:in 'require': no such file to load -- action\_mailer  
(LoadError)  
from smtp.rb:1  
From that I came to know some modules and classes and lib are not  
installed.  
That's why it was telling error.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;In your program is not working properly.It is giving some error.  
My question is that using the smtp how can I sen the email to  
outside.For exampl,rediff,yahoomail.  
we want to require 'net/smtp'  
For me also It is working file within intranet.  
But it is not going outside email.for that I want to know some knowledge  
for sending the outside email.  
This is my question.  
This is my example:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require 'net/smtp'  
from="vellingiri@bksys.co.in"  
to="vellingiri@bkys.co.in"  
smtp=Net::smtp::new('192.168.1.1')  
email="From :vellingiri@bksys.co.in\nSubject : Hello\n\n\Hai,this is  
wrking wery fine.\n\n"  
smtp.start  
smtp.sendmail(email,from,to)  
smtp.finish

I am not asking only sending email using smtp,other than that any  
classes is there.  
But smtp is is not working.  
You want more explanation for this.

by  
vellingiri

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Mohit\_Sindhwani1](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mohit\_Sindhwani1](https://rubytalk.org/u/Mohit_Sindhwani1)\
**Post date:** [17 October 2007 07:38 UTC](https://rubytalk.org/t/how-can-send-email-message-using-ruby/41421/7 "2007-10-17T07:38:15Z")

</div>

Hi. My answers are inline.

Vellingiri Arul wrote:

> Mohit Sindhwani wrote:  
> &nbsp;&nbsp;
> 
> > Vellingiri Arul wrote:  
> > &nbsp;&nbsp;&nbsp;&nbsp;
> > 
> > > > [http://notepad.onghu.com/2007/3/26/sending-email-with-ruby](http://notepad.onghu.com/2007/3/26/sending-email-with-ruby)
> > 
> > Hi, please explain your question more clearly. I think you asked a  
> > similar question in a separate thread (relating to POP) and I don't know  
> > what you require.
> 
> Hi Mohit,  
> Your program Error:  
> &nbsp;&nbsp;&nbsp;smtp.rb:1:in 'require': no such file to load -- action\_mailer (LoadError)  
> from smtp.rb:1  
> &nbsp;&nbsp;  
> OK! My sample actually doesn't use the action\_mailer - it was in the other solution that was proposed to you.

> \>From that I came to know some modules and classes and lib are not installed.  
> That's why it was telling error.  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;In your program is not working properly.It is giving some error.  
> &nbsp;&nbsp;  
> Same as above.

> My question is that using the smtp how can I sen the email to outside.For exampl,rediff,yahoomail.  
> we want to require 'net/smtp'  
> For me also It is working file within intranet.  
> But it is not going outside email.for that I want to know some knowledge for sending the outside email.  
> &nbsp;&nbsp;  
> As I understand it:  
> 1. You have an internal SMTP server that is being used to deliver email.  
> 2. You are using SMTP and it works for internal email addresses.  
> 3. You would like to send email to someone@yahoo.com but that does not work.

If I have understood your problems correctly, it could be a few problems. Since email sending is working internally using SMTP, I think your Ruby script is fine.

The problem could be:  
1. Your internal SMTP server is not set up properly. For some reason, it is not relaying messages to outside parties. In this case, email is not delivered to ANY party outside. This is a configuration problem, not related to Ruby. Check the documentation for the SMTP server that you are using.  
2. If you are able to send out email to some parties externally, and specifically NOT to Yahoo or Rediffmail, it could be that the spam filters at Yahoo, rediff, etc. are blocking your email since it doesn't appear to be coming from a reputable domain. I don't know much about this problem, so I can't help.

Perhaps, someone else can be of more use.

Cheers,  
Mohit.  
10/17/2007 | 3:37 PM.
