# Using /usr/sbin/sendmail in Ruby Script

**URL:** <https://www.ruby-forum.com/t/using-usr-sbin-sendmail-in-ruby-script/179208>\
**Category:** Ruby\
**Created:** [November 19, 2009, 5:15pm UTC](https://www.ruby-forum.com/t/using-usr-sbin-sendmail-in-ruby-script/179208 "2009-11-19T17:15:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [November 19, 2009, 5:15pm UTC](https://www.ruby-forum.com/t/using-usr-sbin-sendmail-in-ruby-script/179208/1 "2009-11-19T17:15:50Z")

</div>

Hi Guys,

I’m very new to Ruby, so please bare with me!

I’m trying to make a ruby script that runs a command/executable. The  
command/executable is native to Mac OS X 10.5 and 10.6. It’s the  
sendmail command (found in /usr/sbin/sendmail). The script I have so far  
is this:

###################################

when “email”  
begin  
job\_media = ENV[‘job\_media’]  
job\_reason = ENV[‘JOB\_REASON’]  
e\_address = get\_node\_value(‘post-action-e-address’)  
eeemail(job\_media, job\_reason, e\_address)  
end

###################################

def eeemail(job\_media, job\_reason, e\_address)

RECIPIENT = removed\_email\_address@domain.invalid  
MEDIA = blah  
REASON = job\_reason  
SUBJECT = “Engine Admin - Job #{REASON}”

exec("/usr/sbin/./sendmail #{RECIPIENT} \<\< EOF  
From: “Episode Engine” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: “#{SUBJECT}”

“Job #{MEDIA} has #{REASON}”  
EOF")

end

###################################

This script will run when a piece of software my company sell, finishes  
a task. The main thing I’m not getting to work is the:

exec("/usr/sbin/./sendmail #{RECIPIENT} \<\< EOF  
From: “Episode Engine” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: “#{SUBJECT}”

“Job #{MEDIA} has #{REASON}”  
EOF")

Any ideas will be greatly appreciated.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [November 19, 2009, 5:20pm UTC](https://www.ruby-forum.com/t/using-usr-sbin-sendmail-in-ruby-script/179208/2 "2009-11-19T17:20:37Z")

</div>

Aldric G. wrote:

> Dan Sinclair wrote:
> 
> > Hi Guys,
> > 
> > I’m very new to Ruby, so please bare with me!
> > 
> > I’m trying to make a ruby script that runs a command/executable. The  
> > command/executable is native to Mac OS X 10.5 and 10.6. It’s the  
> > sendmail command (found in /usr/sbin/sendmail).
> 
> Why not let Ruby do it all?  
> [RubyGems.org | your community gem host](http://gemcutter.org/gems/mail)

…because not all of my customers will have this installed, and as i  
recall from looking at that before, you need to have an SMTP server set  
up too…whereas if i use the sendmail command, it’s already to go with  
Mac OS X…

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [November 19, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/using-usr-sbin-sendmail-in-ruby-script/179208/3 "2009-11-19T17:22:23Z")

</div>

Dan Sinclair wrote:

> Aldric G. wrote:
> 
> > Dan Sinclair wrote:
> > 
> > > Hi Guys,
> > > 
> > > I’m very new to Ruby, so please bare with me!
> > > 
> > > I’m trying to make a ruby script that runs a command/executable. The  
> > > command/executable is native to Mac OS X 10.5 and 10.6. It’s the  
> > > sendmail command (found in /usr/sbin/sendmail).
> > 
> > Why not let Ruby do it all?  
> > [RubyGems.org | your community gem host](http://gemcutter.org/gems/mail)
> 
> …because not all of my customers will have this installed, and as i  
> recall from looking at that before, you need to have an SMTP server set  
> up too…whereas if i use the sendmail command, it’s already to go with  
> Mac OS X…
> 
> Regards,
> 
> Dan

sorry…my bad…looks like i ddin’t read up on that specific ruby mail  
add on…it would still be easier however for my customers to not need  
to install something else.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [November 19, 2009, 5:23pm UTC](https://www.ruby-forum.com/t/using-usr-sbin-sendmail-in-ruby-script/179208/4 "2009-11-19T17:23:35Z")

</div>

Dan Sinclair wrote:

> Dan Sinclair wrote:
> 
> > Aldric G. wrote:
> > 
> > > Dan Sinclair wrote:
> > > 
> > > > Hi Guys,
> > > > 
> > > > I’m very new to Ruby, so please bare with me!
> > > > 
> > > > I’m trying to make a ruby script that runs a command/executable. The  
> > > > command/executable is native to Mac OS X 10.5 and 10.6. It’s the  
> > > > sendmail command (found in /usr/sbin/sendmail).
> > > 
> > > Why not let Ruby do it all?  
> > > [RubyGems.org | your community gem host](http://gemcutter.org/gems/mail)
> > 
> > …because not all of my customers will have this installed, and as i  
> > recall from looking at that before, you need to have an SMTP server set  
> > up too…whereas if i use the sendmail command, it’s already to go with  
> > Mac OS X…
> > 
> > Regards,
> > 
> > Dan
> 
> sorry…my bad…looks like i ddin’t read up on that specific ruby mail  
> add on…it would still be easier however for my customers to not need  
> to install something else.
> 
> Regards,
> 
> Dan

…no no my bad on my bad…lol. It DOES need an SMTP server  
configured.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [November 19, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/using-usr-sbin-sendmail-in-ruby-script/179208/5 "2009-11-19T17:17:20Z")

</div>

Dan Sinclair wrote:

> Hi Guys,
> 
> I’m very new to Ruby, so please bare with me!
> 
> I’m trying to make a ruby script that runs a command/executable. The  
> command/executable is native to Mac OS X 10.5 and 10.6. It’s the  
> sendmail command (found in /usr/sbin/sendmail).

Why not let Ruby do it all?  
[http://gemcutter.org/gems/mail](http://gemcutter.org/gems/mail)

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [November 19, 2009, 5:25pm UTC](https://www.ruby-forum.com/t/using-usr-sbin-sendmail-in-ruby-script/179208/6 "2009-11-19T17:25:43Z")

</div>

Dan Sinclair wrote:

> sorry…my bad…looks like i ddin’t read up on that specific ruby mail  
> add on…it would still be easier however for my customers to not need  
> to install something else.

you could also make your script into a stand-alone executable like such:  
[http://www.erikveen.dds.nl/rubyscript2exe/](http://www.erikveen.dds.nl/rubyscript2exe/)

But, anyway - how is your code failing? have you tried using ‘system’  
instead of ‘exec’ ?

> **[Ruby Kernel system, exec and %x](http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html)**
>
> The Ruby Core Library documentation is very similar for Kernel.system , Kernel.exec and %x\[..\] . Recently I needed to kick off a system pr...
