# How can send email message using ruby?

**URL:** <https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367>\
**Category:** Ruby\
**Created:** [October 16, 2007, 12:30pm UTC](https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367 "2007-10-16T12:30:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 16, 2007, 12:30pm UTC](https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367/1 "2007-10-16T12:30:37Z")

</div>

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.

Thank you

by  
vellingiri.

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 16, 2007, 12:35pm UTC](https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367/2 "2007-10-16T12:35:44Z")

</div>

Vellingiri A. wrote:

> vellingiri.

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:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 16, 2007, 1:59pm UTC](https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367/3 "2007-10-16T13:59:54Z")

</div>

Mohit S. wrote:

> Vellingiri A. wrote:
> 
> > vellingiri.
> 
> 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,  
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

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 17, 2007, 8:25am UTC](https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367/4 "2007-10-17T08:25:39Z")

</div>

Vellingiri A. 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.

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:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 16, 2007, 2:08pm UTC](https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367/5 "2007-10-16T14:08:07Z")

</div>

On 10/16/07, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Vellingiri A. 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 🙂

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  
def simple (from, to, subject, body)  
from from  
recipients to  
subject subject  
body body  
end  
end

SimpleMail.deliver\_simple(‘removed\_email\_address@domain.invalid’, ‘removed\_email\_address@domain.invalid’, ‘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.

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 17, 2007, 8:55am UTC](https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367/6 "2007-10-17T08:55:30Z")

</div>

Mohit S. wrote:

> Vellingiri A. 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.
> 
> 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:  
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.  
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:  
require ‘net/smtp’  
from=“removed\_email\_address@domain.invalid”  
to=“removed\_email\_address@domain.invalid”  
smtp=Net::smtp::new(‘192.168.1.1’)  
email=“From :removed\_email\_address@domain.invalid\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

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [October 17, 2007, 9:38am UTC](https://www.ruby-forum.com/t/how-can-send-email-message-using-ruby/117367/7 "2007-10-17T09:38:45Z")

</div>

Hi. My answers are inline.

Vellingiri A. wrote:

> > 
> 
> Hi Mohit,  
> Your program Error:  
> smtp.rb:1:in ‘require’: no such file to load – action\_mailer  
> (LoadError)  
> from smtp.rb:1

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.  
> > In your program is not working properly.It is giving some error.

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.

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 removed\_email\_address@domain.invalid 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.
