Sending emails by mailer model - ruby-on-rails

I have a database created using Ruby-on-Rails. What I require is a model (perhaps) where I can input some information in a form and then press a button that sends emails to all the users registered in the database. The email contains the details written in the form. Is that possible? Any help will be very appreciated.
Mike

Yes... gather the email addresses in the database. Use the native mailing class for the server technology you are working with. Build the message body as a string (if its a simple email, otherwise you'll want to populate a template file). Create a mail message for whatever server technology you're working with and send to all the gathered emails with the generated body.

Yes yes yes! Rails delivers some great support when it comes to sending emails! using Mailers (you can generate these) all you would need to do is set it up, I would also advice using a gem like mailchimp to test the sent data.
http://guides.rubyonrails.org/action_mailer_basics.html
this tutorial should help you out alot!
Also use your Terminal to fire the Mailers this will make ur process so much faster.
rails console or script/console
rails 2:
MailerClass.deliver_mailer_subclass(passed_parameters)
rails 3:
MailerClass.mailer_subclass(passed_parameters).deliver
Have fun

Related

rails form to send to my email address

On submission of the contact form in my app I am looking to have the form data be sent to my email.
I looked into using action mailer, but on the rails guides it shows configurations for an automated email from you to a new user on signup.
Is there a potential solution out there using simple form?
I can create the form, just need a little help with configuration so it sends to my email.
I appreciate any advice!
You can just do it like a normal form, submit request to your rails server. Then your server collect the data and send email to you using ActionMailer.
If you don't want to do like that, maybe this GEM can help you:
https://github.com/plataformatec/mail_form

Is there a Rails gem that allows a user to send HTML emails via the Rails app?

We want to send emails to registered users on our site.
As of now we programmatically create emails and send them like that, too.
What we would like would be a way that a moderator of the site can create an HTML email using a rich text editor on the Rails app, select users from the database, and send it out.
In essence it would behave a little like a web mailer, like gmail. But: mails would be composed as templates and could use some ERB, so they can be re-used to email users, etc.
A sample application could be a newsletter or a broadcast search that is sent to all, or only some users.
Is there a gem that does this?
If no, how would you set this up?
I don't know of a gem that does this specifically, but you can check out action mailer, which is included in Rails by default.
It's very good for sending out templated emails (account confirmation, etc). You create a view, and it renders the content of that view (with ERB) into the body of the email.
You might be able to use this for more customization, but I haven't played around with it too much.
Another option, if you're programmatically sending mail through the UNIX mail command, is to specify the content type as HTML. The command I use is:
mail -a 'Content-type: text/html' -s 'Subject' to_address#example.com < file_containing_message.html
Ah, sorry -- I didn't understand the question. I don't think there's a gem for your case, because it's a very specific use case.
What I would recommend is storing a blob of ERB text in the database for the email template. Then you can use something like this to render the email:
require 'erb'
name = user.name
email_html = ERB.new(email.template).result(binding)
See the ERB Documentation for more info.

rails 2 actionmailer email address alias

I am working with rails 2 . I wanted to know is there a way in ActionMailer to hide/alias the email address??
Also what should be the best approach for sending bulk emails???
Thanks in advance.
Mailcar
Mailcar 0.1
Mailcar is a dead-simple (ie. not many features) bulk emailer for Ruby on Rails, using ActiveRecord
and ActionMailer.
If you need to send emails to your entire user base and don't want to pay the high prices that most
mass email services charge, then this is the plugin for you!
WARNING!!! Using this without having your SMTP server set up correctly could land your server on
hundreds of blacklists. If that prospects scares you, look at the pay-to-send bulk emailers. It's
expensive, but at least you know you're safe.
WARNING!!! As is, this script is tied tightly to the codebase I wrote it for. It will not work out
of the box. I'm posting it in the hopes that someone else needs something similar and doesn't want to
start from scratch. Please send me patches or pull requests with your upgrades and I'll include them
and add you to the credits.
Installation
To copy the models and create the migration, run:
script/generate mailcar all
Then execute the migration:
rake db:migrate
Example
To send a new bulk email, you must first create the message body file. I use Thunderbird to create an
HTML email, then save it out as HTML.
At that point, you can create the message and send it as follows:
rake mailcar:new_message FROM='me#mydomain.com' SUBJECT='New features on the site' BODY_FILE=/path/to/email/body
rake mailcar:prep_for_send MESSAGE_ID=99
rake mailcar:send MESSAGE_ID=99
If the sending process is ever interrupted, you can resume it with another call to send.
TODO
Add a test suite (wish I knew more about plugin testing...)
Make it easy to give a block (or something) to generate the list of email addresses
Pass emails through ERB to allow for templating / dynamic emails
Add support for multipart emails
Add a cleanup task to remove old messages
Make sending delay configurable

What gem/script can I use to create a email reminder app with Rails & jquery?

I want to create a basic web app where a user can log in and type infortmaion and then set the date and time for a email reminder.
What gem/script can I use to create a email reminder app with Rails & jquery?
Thanks and hope I'm not too vague.
Erin
You could use the delayed jobs gem to schedule a job that will send the email at the appropriate time. And for sending the email itself, you can use ActionMailer.
There are few parts to be consider
E-Mail layout and templates
You should give a try on
liquid (http://www.liquidmarkup.org/) (ruby markup language)
redcloth (http://redcloth.org/) on textile markup
and when it comes to sending mail (as #Chentir mentioned)
delayed jobs
ActionMailer
and you shouldn't miss out followings as well
http://leadthinking.com/233-sending-or-receiving-emails-with-rails
http://railscasts.com/episodes/61-sending-email
HTH
cheers
sameera

Best practices on processing email sent to app specific address in rails?

We would like to implement a feature by which users could send an email to an application specific address and we will parse the message and take certain actions on it, similar to 37signals's backpack (and probably some of their other apps).
If anyone has done something similar, could you fill me in on how you did so? I'm unsure on how to, at a high-level, 'import' the email into the app so that I could process it.
Thank you.
I have recently implemented that exact functionality in rails. I would advice you to look at the 'Receive E-mail Reliably via POP or IMAP' in the the Advanced Rails Recipes book.
I've personally found that the best source for getting this up and running and it explains how to do far better than I can. Good luck which ever way you choose to do it :)
Here's how I fetch from a POP server:
require 'net/pop'
pop = Net::POP3.new('mail.yourdomain.com')
pop.start(account, password)
pop.each_mail do |m|
email = TMail::Mail.parse(m.pop)
email.base64_decode
OttoMailer.process_email_in(email, m.unique_id)
m.delete
end
pop.finish
Why not run a Ruby SMTP mailserver, which will receive the mails via port 25, and then you can parse/interpret etc. as you wish ?
(I say Ruby since that's how you've tagged your question)
An alternative solution is to run procmail (or similar), pattern match on the subject, and then invoke scripts (configured in the .procmailrc file). However that may not scale so well for large volumes of mail.
ActionMailer can receive e-mails as well as send them! I don't remember how this is done but if you look at the documentation you can see it there. But from memory the e-mail gets piped through procmail into a script in the script directory.
There seems to be a book on the subject as well.
Good luck! :)

Resources