# Action Mailer new DSL merged

**URL:** <https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284>\
**Category:** Rails\
**Created:** [January 26, 2010, 3:30am UTC](https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284 "2010-01-26T03:30:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/2bfe46/32.png) [@Mikel\_L](https://www.ruby-forum.com/u/Mikel_L)\
**Post date:** [January 26, 2010, 3:30am UTC](https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284/1 "2010-01-26T03:30:48Z")

</div>

Hi all,

Just letting you know we have a new DSL for Action Mailer.

class Notifier \< ActionMailer::Base  
delivers\_from(“removed\_email\_address@domain.invalid”)

def signup\_notification(recipient)  
@account = recipient

```
attachments['an-image.jp'] = File.read("an-image.jpg")
attachments['terms.pdf'] = {:content => generate_your_pdf_here() }

mail(:to => recipient.email_address_with_name,
     :subject => "New account information")

```

end  
end

Notifier.signup\_notification(recipient).deliver

You can read all about it at:

> **[Mikel Lindsaar](https://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3)**
>
> Internet Home for Mikel Lindsaar

Mikel

–

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar

---

<div class="post-metadata">

**Author:** ![Mikel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/2bfe46/32.png) [@Mikel\_L](https://www.ruby-forum.com/u/Mikel_L)\
**Post date:** [January 26, 2010, 4:26am UTC](https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284/2 "2010-01-26T04:26:23Z")

</div>

Nice.

I’m not sure I understand the new API though. You define instance  
methods but call class methods? Also, what’s that magic recipient  
parameter we never pass in? Why not just define class methods? Eg:

class Notifier \< ActionMailer::Base  
delivers\_from(“removed\_email\_address@domain.invalid”)

def self.signup\_notification(recipient)  
@account = recipient

```
attachments['an-image.jp'] = File.read("an-image.jpg")
attachments['terms.pdf'] = {:content => generate_your_pdf_here() }

mail(:to => recipient.email_address_with_name,
     :subject => "New account information")

```

end  
end

And then do something like

Notifier.signup\_notification(user).deliver

Cheers  
-foca

---

<div class="post-metadata">

**Author:** ![Mikel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/2bfe46/32.png) [@Mikel\_L](https://www.ruby-forum.com/u/Mikel_L)\
**Post date:** [January 26, 2010, 5:30am UTC](https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284/3 "2010-01-26T05:30:11Z")

</div>

Nice work!

---

<div class="post-metadata">

**Author:** ![Mikel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/2bfe46/32.png) [@Mikel\_L](https://www.ruby-forum.com/u/Mikel_L)\
**Post date:** [January 26, 2010, 10:25am UTC](https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284/4 "2010-01-26T10:25:45Z")

</div>

On Tue, Jan 26, 2010 at 5:56 PM, steve ross [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Have you seen this: [gist:281420 · GitHub](http://gist.github.com/281420)

Of course, that was the result of the discussion in campfire we had  
that hashed out the new DSL that José and I implemented 🙂

One change on that though is that delivers\_from is not there, and it  
is replaced with a defaults hash.

–

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar

---

<div class="post-metadata">

**Author:** ![Mikel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/2bfe46/32.png) [@Mikel\_L](https://www.ruby-forum.com/u/Mikel_L)\
**Post date:** [January 26, 2010, 12:31pm UTC](https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284/5 "2010-01-26T12:31:00Z")

</div>

> Just letting you know we have a new DSL for Action Mailer.

I think removing the magic #deliver\_\* and #create\_\* methods, and  
returning an actual Mail object directly by an existing method makes a  
lot of sense.

On the other hand, I think replacing methods like #body, #subject,  
etc. with a hash is a missed idea, it’s harder to write and read, and  
less clear to grasp, especially when you notice that ActiveRecord API  
changes in exactly the opposite direction (from :conditions =\>  
conditions to #where(conditions), etc.).

Are there any more improvements planned on this or is that the final  
version?

–  
Bye,  
Olek

---

<div class="post-metadata">

**Author:** ![Mikel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/2bfe46/32.png) [@Mikel\_L](https://www.ruby-forum.com/u/Mikel_L)\
**Post date:** [January 26, 2010, 7:58am UTC](https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284/6 "2010-01-26T07:58:49Z")

</div>

Have you seen this: [gist:281420 · GitHub](http://gist.github.com/281420)

---

<div class="post-metadata">

**Author:** ![Mikel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/2bfe46/32.png) [@Mikel\_L](https://www.ruby-forum.com/u/Mikel_L)\
**Post date:** [January 26, 2010, 1:26pm UTC](https://www.ruby-forum.com/t/action-mailer-new-dsl-merged/182284/7 "2010-01-26T13:26:01Z")

</div>

On Tue, Jan 26, 2010 at 10:29 PM, Olek [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On the other hand, I think replacing methods like #body, #subject,  
> etc. with a hash is a missed idea, it’s harder to write and read, and  
> less clear to grasp, especially when you notice that ActiveRecord API  
> changes in exactly the opposite direction (from :conditions =\>  
> conditions to #where(conditions), etc.).
> 
> Are there any more improvements planned on this or is that the final  
> version?

You don’t have to pass body as a hash, you pass the body in through  
the template in 99% of the cases.

Think of the mail method as being analogous to the respond\_to method  
in Action Controller.

There are more changes coming, not big, but intelligent ones. Watch  
this space 🙂

–

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar
