How to make a reply address with TMail
November 17th, 2007
TMail is quite an extensive mailing library that is suffering from incredibly documentation pains.
The easy stuff is simple, like @mail.to gives you the to address of the email, and @mail.to=”something” sets the to address to something.
But there are some other things that TMail can do to make your life simple and easy and I am going to document them here on this blog.
Recently there was a bug request 15445 on the create_forward function.
I have fixed this bug and closed the ticket and merged the changes back into trunk of TMail.
But what this means now is that you can do the following:
1 2 3 4 5 |
mail = TMail::Mail.load("/path/to/my_email_message") forwarded_email = @mail.create_forward forwarded_email.to = "New address <me@me.com>" text = "Dear me\n\nHere is that email I was talking about!\n" forwarded_email.body = text |
And then you can just send the forwarded_email.
“create_forward” nicely takes the existing email, encodes it into 7-bit ASCII, and the inserts it as an attachment to a new email which it returns to you… Handy :)
“create_forward” is an existing method that has been moved into the main interface.rb file of TMail which means that it will be available to any mail object with a simple require ‘tmail’ in your ruby or rails code.
Hope you enjoy it!
blogLater
Mikel
November 18th, 2007 at 12:01 AM
Great to see tmail become actively maintained again! (and by a fellow aussie no less :)
I’ve been wanting to ditch the half-assed email code in my ruby-msg project, for something a bit more standards compliant…
Thanks!
November 18th, 2007 at 12:43 AM
@Charles
Thanks :)
I plan to put more up here about TMail as I discover more and more, Minero Aoki definately did a good job with the library.
If you have any problems, let me know.
Mikel