logging the email address in ruby on rails - ruby-on-rails

I wanna log the emails which are being sent from a particular method of the ActionMailer. My ActionMailer consists of many methods which sends email for different reasons, but I to log the emails which are being sent from a particular method and save them in the database.
ActionMailer doesnt allow to do the database operations.
I am newbie to rails ENV,
kindly help me out

You need create your own Delivering system. In this Delivery, you can save your email in your Database and deliver by SMTP or something else.
This method is really not a newbie system. You can create your Delivery like the Mail::SMTP (https://github.com/mikel/mail/blob/master/lib/mail/network/delivery_methods/smtp.rb ) class managing the Delivery system by smtp.

Related

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

Automatically logging email sent through Rails

We send out many emails through Rails (and then through Amazon SES). I'd like to now log all of those emails in our database so we know exactly which emails were sent where and all the details. I'd also love to know which class/method sent those emails or some way to tag them.
This must be an extremely common need, so I'm curious if there's a mechanism with Rails to automatically handle this?
mail-logger gem captures the info about the emails sent, and log them to a file.
With a little bit of work it could be customized to write to a database instead.
The gem is overriding delivered_email method to log the details:
class Mail::Logger::Callback
def self.delivered_email(email)
Mail::Logger.logger.info email.inspect
end
end

In Rails 4 how to store all sent emails with attachments and re-send them again later?

In my Rails 4 application I already store all outgoing emails in DB using an observer. In config/initializers/all_emails_observer.rb I have roughly the following code:
class AllEmailObserver
def self.delivered_email(message)
sent_email = SentEmail.new(
sender: message.from.join(';'),
recipients: message.to,
subject: message.subject
)
sent_email.body = if message.html_part || message.text_part
message.html_part.blank? ? message.text_part.body.raw_source : message.html_part.body.raw_source
else
message.body.raw_source
end
sent_email.save!
end
end
ActionMailer::Base.register_observer(AllEmailObserver)
Now I need to add another feature to let admins re-send any of the emails from the email log.
There are a couple of solutions that I could see right off hand:
Add code to store all attachments (regular and inline), then implement a method that would generate a new email and re-send it. I'm working on this now.
Store the mailer class, mailer method and arguments (serialized using GlobalId, for example). When the admin needs to re-send an email - generate a new email from scratch. I don't like this method because ideally I want re-sent emails to have exactly the same content (including attachments) as when they were originally sent. Mailers could have bugs/typos fixed since, but I do want all those bugs and typos to be still there when an email is re-sent.
Now that Rails 4.2 is released and ActiveJob is stable, I didn't find the standard way to do this: all queued emails are immediately deleted after they are sent (I just checked delayed_job backend). There must be a way to maybe preserve a completed mailer job in some separate DB table and then re-queue that job when needed.
I'd love to re-use the email serialization mechanism of ActiveJob to achieve my goal if possible, because I don't want to re-write my observer when Rails 6 is released with a completely changed observer API.
What is the better way to enable re-sending of sent emails?
Please note that I already reviewed similar questions here:
Save each email before sending rails 4
How do I create a Mailer Observer
However both of them are about how to store sent emails and not about how to re-send them later as is.
Thank you!
Alex.

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.

handle bounced email - ActionMailer

I have a rails app and I am using ActionMailer to send email but now I need to know if the email is delivered or what?
Do anyone has an idea of how to handle sent emails status(e.g bounced, delivered) ?
thanks.
Email service providers use a technique called variable envelope return path. The idea is to encode a unique key for each message into the (envelope) return address so that when a destination smtp server returns email as a bounce you can tie it to the originating message.
If it sounds complex, it is. It gets harder if you want to track response rates, which links were clicked, opens, use Domain Keys, etc. Note that it requires you to set up or configure an SMTP server for handling returned mail.
There are a number of services that provide this all to you on a Software As Service basis. We use socketlabs and are very happy with them. Industrial strength and all. I've also heard of people using Postmark in the Ruby community.

Resources