Single visible recipient when mass-mailing using ActionMailer - ruby-on-rails

I have a Rails 3 application that will send mails out to members of a group.
I would like to be able to send out the mails with a single ActionMailer call but specify all the recipients as an array of addresses, e.g.
Emailer.send_newsletters(['user1#domain.tld', 'user2#domain.tld'])
...
def send_newsletters(addresses)
mail :to => addresses, :subject => 'My newsletter to you'
end
Rails will by default make all the recipients visible when sending the mail but I would like that each recipient only sees his own name instead of all.
I will not use a dummy recipient and BCC all real recipients - it needs to be the right recipient.
Is there any way to send the mails without creating a loop around the addresses myself?

No, there isn't. You can send the email to a list of recipients, but they will see all the other recipients. You can assign the recipients to bcc, but the user won't see its address.
The only way to have the user see its own address is to loop all the elements and send one email for each recipient.

Related

Multiple recipients using Mandrill and Rails

I'm using ruby to send transactional emails via Mandrill.
As part of my product, I want to be able to send the same email to two recipients and have them see each other's email address.
(Like an introduction mail between two people).
So I filled he "to" field with both emails, and on my dashboard is seems that both are sent.
But unfortunately only one of the recipients receive the mail and the details of the second recipient is hidden.
In conclusion, I have two problems:
Only one recipient gets the mail
Hidden details of the second recipient.
I approached Mandrill support and this is what they replied:
If you'd like to enable this option globally for all of the messages you send, then you'll want to ensure that you have the
"Expose The List Of Recipients When Sending To Multiple Addresses"
option enabled in your Sending Defaults.
If, instead of making that change globally, you'd like to enable it
for individual messages, you'll want to use the
X-MC-PreserveRecipients (SMTP header), or the preserve_recipients (API
parameter), and set it to 'true'.
If you set this option to true, we'll expose the list of recipients to
each other as you would see happen when sending mail from a typical
email client program.
It worked!
If you want both recipients to be able to see each other, you can pass an array of e-mails in the to option.
If you do not want either of them to see each other, you can, in a loop over the users, send said e-mail.
If using ActionMailer it can be done like so:
mail(
to: ['person1#gmail.com', 'person2#gmail.com']
)
Or in a loop:
[user1, user2].each do |user|
UserMailer.some_email(user).deliver_now
end
mail(
to: user.email
)
Post your code, I have an idea of what your problem may be. Remember that a method in an ActionMailer class should only return mail() and must not be looped over inside of that method.
tldr: do everything unrelated to e-mail outside mailer, pass through necessary data as params to the method, end method with mail() call.

Catch emails to all a_user_name#mydomain.com, and execute code

In my webapp I have instances where I want to let users send an email to their local representative. But I don't want to expose that user's email so I'd like to have the email sent from a_user_name#mydomain.com, where a_user_name is different depending on who sends it.
Where I'm lost is how to handle the situation where somebody replies to that email, and I need to deliver it to the original author. I'd like to be able to catch that email, look up the user in our database, and send them an email notifying them of the reply. How do I complete this last part?
Using Rails + Amazon SES
Thanks!
You can integrate with a transactional email provider like Mandrill (or others). There's various mandrill rails gems to help.
See: https://mandrill.zendesk.com/hc/en-us/articles/205583197-Inbound-Email-Processing-Overview
The inbound email gets picked up in a controller like:
class InboxController < ApplicationController
include Mandrill::Rails::WebHookProcessor
def handle_inbound(event_payload)
#parse event_payload and take appropriate action
end
end
You can then parse that email to get the sender validate it against your user table and pass the message on or whatever.
You probably want to set a subdomain of your domain or a totally separate domain so you can route your normal email traffic to your mydomain.com mailservers and pick up the emails to be parsed by rails / processed by the webhook from mail.mydomain.com or whatever.
you can use Base64.encode64
2.0.0-p481 :029 > encrypted_email=Base64.encode64('mike#gmail.com')
=> "bWlrZUBnbWFpbC5jb20=\n"
2.0.0-p481 :030 > Base64.decode64(encrypted_email)
=> "mike#gmail.com"
OR MessageEncryptor
2.0.0-p481 :037 > crypt = ActiveSupport::MessageEncryptor.new(Rails.configuration.secret_token)
=> #<ActiveSupport::MessageEncryptor:0xcd4d6fc #secret="c07692942cde247c96ea3da23a4d6406ebdad7c37f63c13e100731ce03ce24088dbe419da154fb7e504e777c60c7f6f8850d27f8cb8b7968602244ce5c21bfb3", #cipher="aes-256-cbc", #verifier=#<ActiveSupport::MessageVerifier:0xcd4d4e0 #secret="c07692942cde247c96ea3da23a4d6406ebdad7c37f63c13e100731ce03ce24088dbe419da154fb7e504e777c60c7f6f8850d27f8cb8b7968602244ce5c21bfb3", #digest="SHA1", #serializer=ActiveSupport::MessageEncryptor::NullSerializer>, #serializer=Marshal>
2.0.0-p481 :038 > encrypted_data = crypt.encrypt_and_sign('mike#gmail.com')
=> "UjF4VFRnRnF1RVJnZXhUUm1KakJZcDFMN1ZoZXVzSmFvLzUwdFkydXNjYz0tLTlsbFI3Vlo4RUNVK2pMZVEzS2tSOWc9PQ==--710d4fcdc202e1b1143e12661d8b40831525f158"
2.0.0-p481 :039 > decrypted_back = crypt.decrypt_and_verify(encrypted_data)
=> "mike#gmail.com"
So.you may use a dedicated table to store both encrypted and original emails and then use it in the FROM section of mail as well as to refer it for future use .So you must use a Generic email id that users can use to reply and then you may send this encrypted hidden field which will identify which email id was intended to send and again send to that email.
i know it would be a two way process like:-
Encrypt email in From part and use Generic email where users can reply back
Use hidden field containing encrypted mail
So,if the user replies back to the Generic mail,check the encrypted mail from hidden field and then again resend it to the decrypted email.
HOPE THIS HELPS.

Rails 4: Send email to an other reciever than in :to

I'm writing a mailinglist software in rails and I want to send a recieved email to all the subscribers.
Normally a recieved email from a mailinglist has the sender in the :from key and the address of the mailinglist in the :to key. So it is easy to see who has written the mail and that this mail is for/from the mailinglist.
I generate the mail (in extracts) this way:
mail[:reply_to] = mailinglist.email
mail.delivery_method.settings.merge!(smtp_settings)
mail.deliver
Now I want to deliver it to subscriber.email, but it is delivered back to the mailinglist (because I don't overwrite mail[:to]). But when I overwrite it with mail[:to] = subscriber.email the email contains not the mailinglist as reciever address.
Is it possible to send an email to a other address than in :to?
Edit:
It is also possible to put all subscribers in :bcc and the mailinglist address in :to, but in this case how can I avoid the sending to the :to reciever?
The way this is usually achieved is to put recipients in BCC field of email (hidden copy) so email actually gets delivered but recipients don't see each other's addresses.

how to add multiple confirmation mail receipents in campaign monitor api used in rails?

If I send the mail to the list of recipients. After that the confirmation mail is send to single person using campaign monitor api.But I want to send the confirmation mail to two or more recipients. could you please answer for this one.
like this:
send = campaign.send!({ :campaignID => campaign.campaignID, :confirmationEmail => #email.from_email, :sendDate => 'Immediately' })
how can i change it for multi recipients.
I don't think Campaign Monitor supports sending multiple campaign confirmations, however you can simply swap out the single email address for an email forwarder on your server which goes to multiple recipients.

How to send emails with return-receipts in Ruby on Rails?

I have to send automatic emails with Return Receipt (aka "acknowledgement of receipt"), to have the confirmation that the receiver have actually received and read the email. The confirmation is a simple email sent to a specified address (the "Disposition-Notification-To" address, given in the email header).
Do you know if there is an easy way to do that with Rails (ActionMailer)? or with Ruby perhaps (TMail, Net/SMTP)?
Thanks in advance for your help.
You set your headers in your mailer def block like so:
headers['Return-Receipt-To'] = 'email#example.com'
headers['Disposition-Notification-To'] = 'email#example.com'
headers['X-Confirm-Reading-To'] = 'email#example.com'
Note that these trigger a dialogue in some, but not all email clients. Also, it is not a guarantee that the receiver actually has read and understood the email.

Resources