ROR : send email using different mail id at different time? - ruby-on-rails

I m new at ROR, so it may be a silly ques.
I'm using ActionMailer to send a mail to any reciepient.
Initially i have tried it using gmail smtp setting.
But in that everytime the mail is sent, it is from the same mail_id.
But in my application I want sender to be different at different time.
So, is it possible to do it using ActionMailer??

Not sure what version of Rails you are on (it shouldn't matter for this one), but this question has already been answered here: Rails and Gmail SMTP, how to use a custom from address

Related

How to setup dynamic email like amp-email in ruby on rails?

I want to setup amp-email in ruby-on-rails. So I can get benefit of dynamic email content.
I have found rails_amp gem and using this I have made changes in mime_types.rb file
Mime::Type.register_alias 'text/html', RailsAmp.default_format
and also made changes in rails_amp.yml file. which is shown below.
targets:
mailers:
and setup a mail with view of amp.erb. But it isn't sending dynamic email and make it html forcefully and mail doesn't have dynamic email symbol.
Can any one please guide me how to setup mailer to send dynamic emails?
It seems rails_amp was last updated almost 2 years ago, before AMP for Email existed, so I believe it doesn't support this format.
For Gmail, you also need to whitelist your sender email following the steps outlined in Test dynamic email.
A little late, but posting here for anyone who comes to this link in future.
I couldn't find a way to test AMP Emails in development environment, so I had to deploy my application live and has domain setup. Then I added TXT records to DNS so that emails can pass Domain Keys Identified Mail (DKIM) and Sender Policy Framework (SPF) authentication.
To test AMP Emails in Gmail, I enabled developer settings and added email from my domain to whitelist it.
Then I configured ActionMailer to send amp, html and text format emails. I have created a blog post here to explain, how AMP Emails can be implemented in A Ruby on Rails Application.

MailBoxer: How should I do make it to send a notification through email?

I am studying a project vish, which has an open source e-Learning platform http://vishub.org, in here, if some one comments another one's Excusion, one email will be sent. This ability is finished by using mailboxer.
But when I run a instance of vish locally, for validate mailboxer, I used a task sending some messages between all users, it worked fine, and I can find the new messages in the header's notification dropdown menu, but I did not get a email when I commented some one Excursion like in vishub, and did not get any error message about mailboxer. According to my newbie experience, I guess that I should config a mail server, but I don't know how to config a mail server for mailboxer, it seems that there is no one discuss about it?
What should I do for enabling mailboxer email? Or any manual should I read? Or my question is not relative to mailboxer? Thanks in advance!
Updated:
According to #rick's reminding, I read some code of mailboxer:
class NotificationMailer < ActionMailer::Base
end
It make me clearer about the relationship between ActionMailer and MailBoxer!
Email wont't be sent in development unless you set config.action_mailer.perform_deliveries = true in environments/development.rb. and also you should use ActionMailer to send email locally. For more information, you can refer this link mailboxer

How to check for bounced emails in rails?

I'm currently creating an email app that is able to send emails to many users. However, I want to know whether there are bounced emails. I'm currently using Amazon SES to notify me if the email is bounced. However, I want the bounced email's data to be automatically entered into my Rails application instead of typing it manually based to the mailer daemons I get from Amazon. Is there are way to do so?
If you are willing to pay, this SaaS site called bouncely seems to provide an interface and an api wrapper around SES bounces.
send_email() returns a response object which can be interrogated for the response metadata.
Compare the status of this with the code you are interested in, perhaps a 550.
I couldn't find any clean existing solution for this, so I wrote a gem (email_events) that allows you to put a email event handler method (including for bounce events) right in your mailer class: https://github.com/85x14/email_events. It supports SES and Sendgrid, so should work for you if you still need it.

Basic Confusion about ActionMailer RoR

I'm fairly new to Ruby on Rails and actually entirely new to website mailing. In a lot of example tutorials I see a "from" object assigned to, for example, "new#example.com". When I setup the emailing functionality on a localhost the RoR command prompt says that everything finished fine even when I keep "new#example.com" as the from object. Can I actually mail from a localhost port? What would I have to put as my "from" address in order to actually send mail from the my local web application? Just a regular email I have? How would it be authenticated to ensure that the "from" address is actually the real address?
It seems a really fundamental concept and I understand all the model/view/controller actions that have to be done to make it work but I'm confused I guess as to how it actually works
In general the from field can be anything.
Some mail servers may take action if they think that you are claiming to be someone you are not, such as blocking mail or marking it as spam (via mechanisms such as DKIM or SPF). These are done at the domain level, ie the mail server tries to work out whether the server talking to it is allowed to send email claiming to be from #example.com.
Other mail servers mail just silently rewrite your from field if they know who you are, for example if you are talking to the gmail smtp servers and have authenticated as bob then the from field will be set to bob#gmail.com, unless it is already set to an email address gmail knows you own.
By default, in development rails doesn't try and send email at all. For it to send email you need to configure the deluvery_method, usually this involves either setting it to :sendmail (if you have an appropriately configured instance of sendmail running locally) or setting to :smtp and also providing details of an smtp server to use.

How do I make ActiveMailer always mail me?

I use ActiveMailer with a 3rd party mailing provider. To develop my app, I want to actually see the emails that come in, as a user would, in my email client.
So in development mode, instead of disabling email, I want my app to send the mails, but change the "to" field so that every email is sent to me. Is that possible?
Update: I want to test the full route my email takes: going through my ESP, arriving in my inbox, viewing it in gmail. I'm not looking to just test that an email is created.
I personally recommend letter_opener by Ryan Bates, however, if you actually want to deliver the mail instead of just viewing it in the browser, there are a number of plugins available that others have already listed. No one, however, has mentioned that you can very easily accomplish this using Interceptors.
Create a new initializer in your config/initializers directory in your Rails app:
# config/initializers/development_mail_interceptor.rb
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.subject = "[#{message.to}] #{message.subject}"
message.to = "YOUR_EMAIL#gmail.com"
end
end
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
This leverages the power of an interceptor on your app. It doesn't configure anything, but rather changes the envelope on the message, altering the to and subject fields. Replace YOUR_EMAIL with the correct value.
The self.delivering_email(message) method is invoked by ActionMailer. You are hooking into that method and override the message envelope.
Finally, you register that interceptor iff we are currently in the development environment.
Be sure to restart your server, and all your mail (in Development) will actually be sent to your email.
Save yourself some trouble and run MailCatcher. MailCatcher is a simple SMTP server that just grabs outbound email and gives it to you in a simple web interface. Install MailCatcher, add this to your environments/development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :host => 'localhost', :port => 1025 }
Start MailCatcher when you start your Rails server (or use Foreman or something similar to deal with it), and then go to http://localhost:1080/ to see the email that your application is sending out.
You may consider checking out something like MockSMTP (OS X); instead of modifying your "to" fields, you instead set the mail server for dev mode to the "fake" SMTP server created by the app, and from then on ALL emails (sent to anyone) go instead to the app.
I've never used it myself, but I remember seeing that the devs at 37signals use it.
On other operating systems, you may consider one of the following projects:
letter_opener by Ryan Bates - popup a new browser window when an email is sent
MailCatcher (mentioned by mu is too short) - runs a fake SMTP server and a web-based interface for viewing mail sent to it
mailtrap - similar to MockSMTP, has both a mock SMTP server and also a separate viewer program
As much as I like this answer, I went with a different option.
Use the mail_safe gem! As well as providing the functionality from sethvargo's answer, it doesn't require any work other than adding the gem, and it automatically figures out who to email from their .gitconfig.
One important note that I rarely saw mentioned when researching this is that you must use deliver, not deliver!. The latter doesnt call interceptors (though apparently it still calls observers, if that's helpful).

Resources