# Send email when a error occurs

**URL:** <https://www.ruby-forum.com/t/send-email-when-a-error-occurs/102734>\
**Category:** Ruby\
**Created:** [March 30, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/send-email-when-a-error-occurs/102734 "2007-03-30T20:52:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [March 30, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/send-email-when-a-error-occurs/102734/1 "2007-03-30T20:52:27Z")

</div>

I have a script in ruby that build a software for me once per day and  
when the code is wrong and a error, I don’t if the error has ocurred and  
I don’t know what happened.

I wanna know how I can saw the error, I want that this script tell me  
what happenend by email.

Thanks,

Ivan

---

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [March 31, 2007, 1:15am UTC](https://www.ruby-forum.com/t/send-email-when-a-error-occurs/102734/2 "2007-03-31T01:15:14Z")

</div>

On 3/30/07, Ivan V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a script in ruby that build a software for me once per day and  
> when the code is wrong and a error, I don’t if the error has ocurred and  
> I don’t know what happened.
> 
> I wanna know how I can saw the error, I want that this script tell me  
> what happenend by email.

Search for the docs on Net::SMTP in the ruby standard library.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [March 31, 2007, 10:42am UTC](https://www.ruby-forum.com/t/send-email-when-a-error-occurs/102734/3 "2007-03-31T10:42:52Z")

</div>

On Sat, Mar 31, 2007 at 03:52:29AM +0900, Ivan V. wrote:

> I have a script in ruby that build a software for me once per day and  
> when the code is wrong and a error, I don’t if the error has ocurred and  
> I don’t know what happened.
> 
> I wanna know how I can saw the error, I want that this script tell me  
> what happenend by email.

How are you running it daily? If running from cron, then cron should  
capture  
your script’s output and mail it to the cron user’s uid.

Otherwise you could do something like  
IO.popen(“sendmail removed\_email\_address@domain.invalid”,“w”) do |io|  
io \<\< EOM  
From: system@yourhost  
To: removed\_email\_address@domain.invalid

Something nasty has happened!  
EOM  
end

YMMV (you didn’t say if this was Windows or Linux/Unix or something  
else)

B.
