# Internal mail system

**URL:** <https://www.ruby-forum.com/t/internal-mail-system/88504>\
**Category:** Rails\
**Created:** [March 12, 2007, 5:34am UTC](https://www.ruby-forum.com/t/internal-mail-system/88504 "2007-03-12T05:34:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![darrenevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@darrenevans](https://www.ruby-forum.com/u/darrenevans)\
**Post date:** [March 12, 2007, 5:34am UTC](https://www.ruby-forum.com/t/internal-mail-system/88504/1 "2007-03-12T05:34:35Z")

</div>

Hi

I would like to develop a small internal messging system (using user  
ids) for a web site I have developed so that users can communicate with  
each other using a messaging system. I envisage main menus of: new,  
sent, inbox with all of the usual features in these sections included  
(eg. delete, delete all, reply, forward). Users should be able to send  
messages to users that they have predefined on a list.

Before I undertake quite a lot of development, I wondered whether anyone  
had done this already and would be prepared to share the code or if  
anything is commercially available to integrate into my application?

I don’t really want to start re-inventing the wheel if there is an easy  
solution.

Any advice on how best to proceed would be really appreciated.

Many thanks

Darren

---

<div class="post-metadata">

**Author:** ![darrenevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@darrenevans](https://www.ruby-forum.com/u/darrenevans)\
**Post date:** [March 12, 2007, 11:32pm UTC](https://www.ruby-forum.com/t/internal-mail-system/88504/2 "2007-03-12T23:32:07Z")

</div>

Darren E. wrote:

> I don’t really want to start re-inventing the wheel if there is an easy  
> solution.

A blog, right? Just install Mephisto or one of the others. Blogs with  
message boards are where it’s at. Even simpler, a Wiki. The Recent  
Changes is the daily inbox.

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![darrenevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@darrenevans](https://www.ruby-forum.com/u/darrenevans)\
**Post date:** [March 13, 2007, 6:16am UTC](https://www.ruby-forum.com/t/internal-mail-system/88504/3 "2007-03-13T06:16:01Z")

</div>

Hi Phlip

Thanks very much for your reply, I really appreciate it. Mephisto looks  
really interesting, but it’s not exactly what I am looking for this  
time.

I would like a system where one user sends a message to another user,  
rather than one user sends a message to all users. Something like an  
internal email system within the application is the best way that I can  
describe it, but using user ids rather than e-mail addresses

Maybe I could adapt Mephisto by adding some conditions, or is there  
something more appropriate?

Thanks

Darren

Phlip wrote:

> Darren E. wrote:
> 
> > I don’t really want to start re-inventing the wheel if there is an easy  
> > solution.
> 
> A blog, right? Just install Mephisto or one of the others. Blogs with  
> message boards are where it’s at. Even simpler, a Wiki. The Recent  
> Changes is the daily inbox.
> 
> –  
> Phlip  
> [http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![darrenevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@darrenevans](https://www.ruby-forum.com/u/darrenevans)\
**Post date:** [March 14, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/internal-mail-system/88504/4 "2007-03-14T19:50:56Z")

</div>

Darren E. wrote:

> > –  
> > Phlip  
> > [http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

Yup, I’ve implemented one. Really easy to roll your own, particularly if  
you’re using REST. My model is really simple, with just a few  
validations and utility methods:

class Message \< ActiveRecord::Base  
validates\_presence\_of :title, :body, :recipient\_id, :sender\_id  
belongs\_to :sender, :class\_name =\> “User”, :foreign\_key =\> “sender\_id”  
belongs\_to :recipient, :class\_name =\> “User”, :foreign\_key =\>  
“recipient\_id”  
attr\_accessible :title, :body, :recipient\_id

# aliases read\_at accessor attribute to make it read more nicely

def read?  
read\_at  
end

# returns the opposite\_party in the messsage to given user. So if the

given user is the recipient,

# this method returns the sender and vice versa. If the given user is

neither a recipient nor sender

# (e.g. because they’re an editor) it returns the recipient. If the

given user is nil (e.g. because

# the current\_user is nil) an exception is raised

def partner\_to(user)  
raise ArgumentError unless user  
user.id == recipient\_id ? sender : recipient  
end  
end

In User model (which is based on acts\_as\_authenticated), I’ve got the  
following associations:

has\_many :sent\_messages, :class\_name =\> “Message”, :foreign\_key =\>  
“sender\_id”, :order =\> ‘created\_at DESC’  
has\_many :received\_messages, :class\_name =\> “Message”, :foreign\_key =\>  
“recipient\_id”, :conditions =\> [‘deleted\_at IS NULL’], :order =\>  
‘created\_at DESC’  
has\_many :unread\_messages, :class\_name =\> “Message”, :foreign\_key =\>  
“recipient\_id”, :conditions =\> [‘read\_at IS NULL AND deleted\_at IS  
NULL’], :order =\> ‘created\_at DESC’

The schema for the Message class is:  
create\_table “messages”, :force =\> true do |t|  
t.column “title”, :string  
t.column “body”, :text  
t.column “recipient\_id”, :integer  
t.column “sender\_id”, :integer  
t.column “created\_at”, :datetime  
t.column “deleted\_at”, :datetime  
t.column “read\_at”, :datetime  
end

Hopefully should be enough to get you started.

---

<div class="post-metadata">

**Author:** ![darrenevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@darrenevans](https://www.ruby-forum.com/u/darrenevans)\
**Post date:** [September 14, 2007, 12:59pm UTC](https://www.ruby-forum.com/t/internal-mail-system/88504/5 "2007-09-14T12:59:25Z")

</div>

Darren E. wrote:

> Chris,
> 
> Thank you very much for this. It looks like an excellent start for me to  
> build on.
> 
> Darren

Hi All:

I am also looking for the same internal messaging application. N  
wondering if any such functionality is already available with ROR.

Any help will be highly appreciated.

Thanks and Regards,  
Priya S.

---

<div class="post-metadata">

**Author:** ![darrenevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@darrenevans](https://www.ruby-forum.com/u/darrenevans)\
**Post date:** [September 17, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/internal-mail-system/88504/6 "2007-09-17T15:12:14Z")

</div>

I found this  
[http://matt-beedle.com/2007/06/05/acts\_as\_emailable/](http://matt-beedle.com/2007/06/05/acts_as_emailable/)

But can someone tell me whether this is ok to use? or has someone used  
it?

also…how do i take mephisto’s emailing feature???  
pls let me know.

On Sep 14, 3:59 pm, Priya S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![darrenevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@darrenevans](https://www.ruby-forum.com/u/darrenevans)\
**Post date:** [October 8, 2007, 9:02pm UTC](https://www.ruby-forum.com/t/internal-mail-system/88504/7 "2007-10-08T21:02:39Z")

</div>

Hi,

I have been using my acts\_as\_emailable plugin on a number of sites which  
I am currently developing and it has working fine for me so far. It  
only gives you the models and associations though, you will need to  
write the views and controllers yourself. This is very simple to do  
though. I have written some examples on my blog here  
[http://matt-beedle.com/2007/06/05/acts\_as\_emailable/](http://matt-beedle.com/2007/06/05/acts_as_emailable/).

One thing this plugin does not allow you to do however, is to send a  
message to multiple users, like a myspace bulletin. Well, it could be  
done, but with lots of data duplication. Please get in contact if you  
need any help with this and I’ll be more than happy to lend a hand.

Regards,

Matt

---

<div class="post-metadata">

**Author:** ![darrenevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@darrenevans](https://www.ruby-forum.com/u/darrenevans)\
**Post date:** [March 15, 2007, 8:13am UTC](https://www.ruby-forum.com/t/internal-mail-system/88504/8 "2007-03-15T08:13:28Z")

</div>

Chris,

Thank you very much for this. It looks like an excellent start for me to  
build on.

Darren
