rails sending bulk mails - ruby-on-rails

We are using Rails 2.3.8 version. In our application, we tend to send individual email to all users ( around 1500 users - Bulk email ). We are not using any services other than Actionmailer. Hence, we cannot use any service (like mailGun, sendGrid, mailchimp, etc) Also, we have our own SMTP server, through which all the mails are sent.
We have added our mailing functionality to be executed in two scenarios.
Rake Task with CRON JOB ( Auto mails to be sent at specific time)
Via controller ( Mails are sent when a button is clicked)
In both the cases, Initially, the mails are forwarded to the users without any issues. As the user count increases, suddenly the mail functionality stops and throws either of the two following errors.
535 5.7.3 Authentication Unsuccessful
Execution expired
Could anyone please help me sort out the issue?
Is there any timeout value that has to be set for SMTP server connectivity? Or are there any restrictions (like number of mails sent per minute) ?
Thanks in Advance

Related

Sendgrid Inbound Webhook - Undelivered notification

As per sendgrid documentation, the way Inbound parser webhook responds to failures are that it will retry to post the email to the configured endpoint for 3 days and will drop the email if undelivered.
The Parse API will POST the parsed email to a URL that you specify. If a POST is unsuccessful, SendGrid automatically queues and retries any POSTs that respond with a 5XX status. This prevents data loss for customers who have misconfigured their website or POST URL.
Respond with a 2xx status to the POST request to stop the email from retrying.
To avoid returning an error your link must return a 2xx HTTP code when the email is received. This response lets our system know that your link has received the email. It is then removed from our send queue. If we do not get a valid 2xx HTTP response, our servers will believe they have failed to deliver your message. Messages that cannot be delivered after 3 days will be dropped.
I would like to know if before dropping the undelivered emails, will sendgrid notify the sender that their email could not be delivered?
Based on a few tests I ran, it does not appear SendGrid will ever send a notification to the sender, nor is there any easy way to ascertain whether SendGrid has dropped any inbound emails.
Although the documentation wording is slightly ambiguous, my understanding based on testing (which aligns with the documentation wording) is this:
Server returns 2xx: email is deemed accepted, no further attempts made.
Server returns 5xx: server has error, attempts made until 2xx is returned (see below for timing of subsequent attempts), or 72 hours lapses
Server returns any other response, or DNS records do not exist: email is deemed failed, no further attempts made.
My conclusions are based on a number of tests I ran over the course of a week, from which I ascertained the following:
Case 1. Parse server returns 400 or 403 error
The email is dropped after one attempt.
No further attempts are made to POST the email.
No notification is sent to the sender or to the SendGrid account.
(Test method: Configure SendGrid to a URL that returns one of the above error codes. Checked server logs over 1 week, and noted only one attempt was made.)
Case 2. The parse hook URL does not have a DNS record
The email is dropped, presumably after one attempt.
No notification is sent to the sender or to the SendGrid account.
(Test method: configure the hook URL to a subdomain that does not have any DNS records. Run DNS search and try opening the hook URL to confirm the DNS records do not point anywhere. Send an email. Then, after 12 hours, add an appropriate record to the subdomain to point it to a script. Checked server logs and confirmed no attempts were made to POST the email. A subsequent email attempt successfully POSTed.)
Case 3. Parse server returns 500 error
SendGrid attempts to POST to the hook URL at the following intervals:
+0 +5m +10m +15m +20m
+25m +35m +50m +1h20m +2h20m
...then every 3 hours
The last attempt occurs +71h20m
The 20 min offset is a bit unusual, but it falls on the hour, so it may be because the message is queued to attempt POSTing on the hour.
No further attempts are made to POST the email after 72 hours.
No notification is sent to the sender or the SendGrid account.
Statistics
The documentation refers to the availability of statistics, however, I have found the numbers to be inaccurate.
For example, during my testing, I had a number of emails go through the API, including some that were intended to be successful (and did indeed POST to my server) and a few that were intended to fail (as part of the above testing), however, the numbers returned did not align.
Takeaways
Care should be exercised in the following scenarios:
Server downtime: this would ultimately depend on how the server is configured. If the server returns a 5xx response code, SendGrid will keep trying to POST the email. I also tried to test a timeout scenario, however, SendGrid seems to be very patient (e.g. I made my script pause for 10 minutes, SendGrid kept the connection for 10 minutes, though interestingly, due to the second attempt occurring after 5 mins, the email POSTed twice).
Server misconfiguration that returns 4xx error codes. SendGrid will drop the email.
It should also be noted if an email is dropped, there doesn't appear to be any reliable method of finding this out.
SendGrid won't send a notification before the email is dropped. However, the message will be dropped only after receiving an error from your Webhook URL and retrying to post the message for three days.
We got a confirmation from the Sendgrid support team, that the emails that are dropped in the Inbound Webhook Parser feature, will not have any notification or being saved in Sendgrid. So, we won't be able to get any info regarding the emails which are dropped.

Rails 5 retry sending email if exception is raised during the send email action

What is the standard way or configuration option for Rails 5 application to retry sending an email if it raises an exception during sending the email?
I expect some option to retry sending a number of times but couldn't find anything like that.
More details:
I got this error while sending an important email, it happened only once since months but that is an important email, so I would like to increase reliability of sending the emails by retrying if some exception happens (like network issue or my smtp provider couldn't receive my email or any similar reason)
451 Authentication failed: Could not authenticate
I'd recommend to use delayed_job gem for the purpose.
When you want to send an email you would need to call delay method.
Mailer.delay.your_method
it will create a record in database that will be executed in background.
If a background job fails, the error will be saved for the row. You can configure MAX_ATTEMPTS number for delayed_job server. If no errors while sending - record will be deleted from the delayed_jobs table.

How To Test Sending Thousands Of Emails

I'm developing an application that will send thousands of emails per day based on a CSV file using Amazon SES.
My client would like to send around 50,000 in one hit.
The app is almost done however i would like to test it with thousands of emails. What a shame would it be that on my first try with live data it doesn't work.
Right now i have only tested it using about 10 emails in my CSV file.
Does anyone know of a way to test sending around 10,000 emails? Obviously i can't use real data.
I believe you can use real data. To test 10,000 emails for example, you can do the following (assuming you've already increased your SES sending limits):
Generate 10,000 email recipients in your CSV file for a target domain that you already manage. Those 10,000 email addresses should be random and non-existent (e.g., 1eed1417-cc2c-4f7c-8ddb-7e0dfbcacb31#mydomain.com).
Configure a catch-all email address for mydomain.com (e.g., catch-all#mydomain.com) to receive emails sent to any non-existent address.
Add SES SMTP servers to mydomain.com's trusted senders/addresses and make sure your mailserver's throttling rules allow this sending volume.
Test during off-peak hours and check the inbox of your catch-all mailbox.
What i ended up doing is using https://mailtrap.io/
I made 25 emails. Then sent 600 emails to each of the 25 emails. That equals 15,000.
I didnt use action mailer to send the emails. I used the Amazon SES send email method
def send_email!
client.send_email(email_attributes)
end
private
def client
Aws::SES::Client.new(region: Rails.application.secrets.ses_region,
access_key_id: Rails.application.secrets.aws_access_key_id,
secret_access_key: Rails.application.secrets.aws_secret_access_key)
end
Used Kabana for tracking the emails. If they bounced, delivered and so on.
SES won't track email opens so we have a small Node-JS app that will track opens and clickable links.
The app sends around 15000 emails in 20minutes.
I am assuming you are not doing a full end-to-end test (which includes checking to ensure the email was received) but rather are just performing a functional test of your application logic.
If that is the case,
Point your application at a test email server and disable outbound email for all queues. You could also do this on a production server, at say 3:00 am, I guess, but be careful!
Run the application
Check the email server's outbox and count the number of items that have queued up.
If the count matches, your test has passed.
Don't forget to purge the queue before turning it back on!

Mandrill is ghosting accounts or am i incorrect - it says delivered however mandrill did not even tried to send emails

I am using free mandrill account and sending email via using template and API
When i send message it returns okay it is sent as status
However even after several days there is still no smtp events at mandrill interface and the email is not arrived
So i am 100% suree mandrill is ghosting accounts
Or there is something else that i do not know?
Thank you for answers
PS: At the beginning emails were arriving but after some point no smtp events and no emails ever arrived even though no error message parsed. Also when i send to non existing email no bounce message returned.
Also account reputation is 61 : excellent
Yes i believe mandrill certainly ghosting accounts
After trying with several accounts i am now sure of it
Even if you send to non existing gmail email, it says delivered in its interface
However it should have displayed hard bounced
So beware of their free service. I believe this is not an ethical way of working. People would think that their emails are arriving however they are ghosted and mandrill did not even try to send them and yet displays delivered
Have you check it on Mandrill account? It shows all the report at outbound tag. The reason is, a queued response in the Mandrill API is not the same as a queued response from a recipient server.
When you send a message through Mandrill, you first relay it to Mandrill, Mandrill processes it, and then Mandrill relays it to the recipient server. This all happens quite quickly, but the two relaying steps are separate and distinct. The KB article you've linked to is providing additional details on that last step, relaying to recipient servers, not a queued status for the Mandrill API.
There are a number of reasons the Mandrill API may respond with queued including if you've added attachments or if you're sending to a bunch of recipients in a single API call.
Without seeing the actual API call that's being made, it's hard to say why you're getting a queued response. But if you're using the sample messages/send API call, you'll want to remove all of the optional parameters that you're not actually setting. For example, the sample has fake attachments, and a subaccount specified. The attachment will cause the call to be processed async. The subaccount probably doesn't exist, and would then cause the call to fail. So if that's the case, try removing all of those optional params. If not, please provide the API call you're making with sensitive data redacted (API key, actual email addresses).

Net::SMTPUnknownError (could not get 3xx (550)) error when sending email on my Rails app

I'm using google for sending emails on my Rails 3.2 app. Most emails functions were working perfectly. Then I did some testing because delayed_job is not working. I got a warning from google that I need to log into the account via the web to unlock it (I sent about 20 emails in a span of 1 hour). Things were back to normal. Now, I am unable to send any emails whatsoever. I have this error message in my server log:
Net::SMTPUnknownError (could not get 3xx (550))
Has Google blacklisted me for sending 50 emails? I changed the password on the account, logged in a few times via the web, restored the settings to exactly what they were when the emails were working.
I got email working again by creating a new email address. Had to create a new one without using an alias for the old one to get it to work. I also created an SPF record entry, which I did not have before.

Resources