# Any capistrano email recipes?

**URL:** <https://www.ruby-forum.com/t/any-capistrano-email-recipes/87666>\
**Category:** Rails\
**Created:** [March 5, 2007, 1:53am UTC](https://www.ruby-forum.com/t/any-capistrano-email-recipes/87666 "2007-03-05T01:53:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 5, 2007, 1:53am UTC](https://www.ruby-forum.com/t/any-capistrano-email-recipes/87666/1 "2007-03-05T01:53:15Z")

</div>

I’d like to set up capistrano to send an email whenever we do a  
deployment. Just start an SMTP session with localhost and shoot off  
the email. I have all the code to do that actually, I just don’t know  
how to run some Ruby code on the deployment server. Anyone know how  
to do that, or do you have an email recipe?

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 5, 2007, 2:17am UTC](https://www.ruby-forum.com/t/any-capistrano-email-recipes/87666/2 "2007-03-05T02:17:16Z")

</div>

On Mar 4, 2007, at 4:52 PM, Pat M. wrote:

> I’d like to set up capistrano to send an email whenever we do a  
> deployment. Just start an SMTP session with localhost and shoot off  
> the email. I have all the code to do that actually, I just don’t know  
> how to run some Ruby code on the deployment server. Anyone know how  
> to do that, or do you have an email recipe?
> 
> Pat

Hey Pat-

Here is a method you can use to run ruby code on the remote server:

def ruby(cmd, options={}, &block)  
temp\_name = random\_string + “.rb”  
begin  
put(cmd, temp\_name, :mode =\> 0700)  
send(run\_method, “ruby #{temp\_name}”, options, &block)  
ensure  
delete temp\_name  
end  
end

# then in a recipe:

task :foo do  
ruby “puts ‘hello world!’”  
ruby \<\<-RUBY  
1.upto(10).do |i|  
pust i  
end  
RUBY  
end

Cheers-  
– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 6, 2007, 1:01am UTC](https://www.ruby-forum.com/t/any-capistrano-email-recipes/87666/3 "2007-03-06T01:01:18Z")

</div>

On 3/4/07, Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> ```
> put(cmd, temp_name, :mode => 0700)
> ruby "puts 'hello world!'"
> 
> ```
> 
> – removed\_email\_address@domain.invalid  
> – Engine Y., Serious Rails Hosting  
> – (866) 518-YARD (9273)
> 
> >

Cool, thanks, that worked. Until I needed to load up some stuff from  
the rails environment. Decided to use ActionMailer instead of just  
doing the SMTP connection. Anyway, I created a cap plugin:

module CapistranoRunner  
def runner(cmd)  
run “#{release\_path}/script/runner "#{cmd}" -e production”  
end  
end  
Capistrano.plugin :runner, CapistranoRunner

and then to use it it looks like

task :after\_deploy do  
runner.runner “CapistranoMailer.deliver\_deploy(:revision =\>  
#{revision})”  
cleanup  
end

Pat
