SparkPost suppression error and mail stops sending - django

I am using SparkPost for one of my Django website to send mails to users.
I had an update on site so sending mails to all users.
However few of users have deleted their Gmail id from Gmail and I understand that mails cannot be sent to those ids.
However problem I am facing is that in Django, SparkPost stops sending mails to all users once a single mail fails because of this.
Error message is this:
Message generation rejected Code: 1902 Description: recipient address was suppressed due to system policy

That specific error ...suppressed due to system policy is SparkPost saying that it decided not to send to a particular recipient address because it appears on its Global Suppression List. You can read about it here but basically, no-one should send email to addresses on that list so SparkPost rejects mail for them to avoid an later reputation damage.
That issue alone shouldn't stop all mail from flowing though. Here are a few other options to check out which would have that effect:
What error does SparkPost produce for the other failing messages?
Has your account been suspended? Log in to check.
Does your API key have correct privileges?
As an aside, you could also ask this question on the SparkPost Community Slack team.

You need to clean your mailing list prior to sending out mass mailings. This will weed out stale and unreachable emails to prevent bounce in the first place.
If you are using SparkPost lists, you can just use MailboxValidator to import and clean your list for you.
https://www.mailboxvalidator.com/resources/articles/how-to-import-email-list-from-sparkpost/
If you're not using SparkPost lists, you can dump out your mailing list and just upload into MailboxValidator for cleaning then you can just import the cleaned list back into your system.

Related

AWS SES: How to handle bounces for Transactional emails?

When it comes to marketing emails, when you receive a bounce or a complaint, you should simply remove the email address from the mailing list if it is a hard bounce or spam complaint.
However, how does AWS expect you to handle bounces or complaints from transactional emails (like a forgot password email), since there is no mailing list?
For Bounce, you can use third-party APIs like zero bounce, etc. before sending the emails.
For complaints, if you are getting who are marking the mails as spam then stop sending them the emails. If not then there are many different ways of finding it through Amazon services itself.

Django+Twilio: How can I display inside my django app the sms I sent/received using twilio? (Architecture question)

I have a high level architecture question:
I have a django app where users can send out sms to their contacts (telephone numbers, not users of my app). I am trying to implement a system where if someone replies to a specific text, such reply is forwarded to the user that started the thread.
I implemented an inbound webhooks to receive sms but I am now facing a problem: how do I know which text is a reply replying to? I can't seem to find any type of id in the sms inbound request and I am now starting to fear that this is just impossible.
Any idea? Should I try to use "Conversations"? Would that solve my problem and if so, how should I go about it?
Any suggestion?
Twilio developer evangelist here.
You cannot get the message that a user is replying to, because that doesn't exist in SMS. SMS messages are simply chronological. To test for yourself, open your SMS app and try to reply to the second to last message from someone.
You have a few options to try to tie a reply to a specific message:
Only ever send one message to be replied to at a time. Once you receive a reply to one message (or there's a timeout of some sort), send the next one.
Have the user enter a message identifier in their message. You can then parse the identifier out and associate the reply. This is not very user friendly and they may forget or get the wrong identifier in the message
Use multiple numbers to send the messages. So, if you have an active message you are waiting for a reply to, use a different number to send out the next message. You can then associate the reply based on the number the user replies to.
The last option is my preference since it doesn't affect the messages you can send at any time and doesn't require extra work on behalf of the user. It does require extra work to build a number pool and do the work to associate messages with sending numbers.

How to setup an email address for sending only?

My main goal is to setup an email address for my server to use for sending emails only.
I did some research, and it looked like Amazon Simple Email Server and/or Amazon Workmail could provide me with what I needed. I've gotten as far as setting up SES and Workmail so that I can set my server to be able to send emails. However, I saw that once the Workmail inbox is full (50GB), the account would be unable to send emails. Given that this is going to be used by the server and not a human, I didn't want the inbox to get filled with auto replies, spam, or failed to send messages, and then be unable to send emails. So, I went looking for a way to either:
A) prevent emails from being received and stored in the inbox
B) a rule I could setup to delete anything that didn't match the company domain
C) be able to read the inbox and delete email messages using the AWS CLI, and I'd setup my own script to manage how and what was deleted when
So far I haven't had any luck.
Again, I'm not particular how I achieve the goal, but I do preferably need to find a way to have an email address for a server to use exclusively for sending messages. I worry that if I leave it to employees to remember to login and clear the inbox, someone will forget, and then the server will stop sending emails.
Any direction or advice would be greatly appreciated.
I'm not well versed in email protocols; could I setup the address to return a bounce back always, and that would prevent it from receiving emails into it's inbox?
How are you generating these emails? If you are generating them programmatically (via an app/script), you may not need to set up a server. If you just route the outgoing mail through your app to SNS, the emails will be valid, however, there will be no "inbox" for incoming mail and they will just be dumped. This way you don't have to actually worry about an inbox getting full as it will just drop anything coming in.
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email.html
In order to receive emails though SNS, you have to go through the setup linked above, but if you do not set this up, then emails will just bounce. At least, that is how I have been doing it.

Amazon SES does nothing

I'm trying to use the Amazon SES sendTemplatedEmail function.
I have:
verified the sending domain
verified various emails (company, google, gmx)
am in the sandbox
created all the templates
send test emails and verification emails and they went through
I do:
send out emails to the same email as the sender and receive a valid message id
to a company email and receive a valid message id
to a google email and receive a valid message id
to a gmx email and receive a valid message id
No emails are getting delivered and none occur in the send statistics.
What can I do now in order to debug that?
Update
I found a "RenderingFailure" in CloudWatch, and that hints to the error. I can't find the actual error, though.
Took me a while to finally debug this.
I ran this command to test out the template rendering:
aws ses test-render-template --template-name myTemplate --template-data "{\"key\":\"value\"}"
This finally showed me what was wrong (I referenced a {{token}} which wasn't defined in my template-data.
If anyone at AWS is reading this please either default to an empty string or at least show an error message while sending!
This is called Rendering Failure which happens when the template data you passed doesn't match with the template variables you have in your template. You can set SNS notification so that you get notified anytime this rendering failure occurs.
I have written a blog to tackle this. Please have a look at https://dev.to/nabinadhikari/aws-simple-email-service-caveat-5jn

How would I know that email has been sent or not via SendGrid in Django

I am working on django and sending emails to multiple users at once. in the given scenario it only tells me that if it has sent or not.
I want to display the report of same page that how many emails has sent to user successfully and how many not. more if i want to get details why email has failed to sent.
How would i do such things via SENDGRID APIs.
There are two options that I know of:
Connect to SendGrid Event Webhooks and start parsing events for every email to flag ones that were not sent. I believe you can configure SendGrid to only send certain events, so if you're interested in bounces you don't need to worry about handling all events.
The second option is to use a service like sendwithus which will connect to your SendGrid account on your behalf and track all bounces/opens/clicks for you and provide a simpler API/UI to view the data. I believe they do this via SendGrid's webhooks, so it's effectively the same solution but written for you.
Happy to elaborate on either, I've used both before.