How would I know that email has been sent or not via SendGrid in Django - 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.

Related

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.

Send email with custom from with amazon ses for several domains

How can I accomplish to send email in Amazon SES with a custom email from for several domains.
For example, I have an application that is used by several clients, and we have a module to send emails. When we send an email it goes with the "amazonses.com domain", but what I want to accomplish is a custom from email for each client, each one has a different domain.
The process for doing this is entirely specific to the current SES configuration steps so its better I provide a link thats regularly updated.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/mail-from-set.html
The short summary is that you can do this by choosing a FROM option for the emails you are sending from.
Programmatically Setting From
The link above points how how to use the API to programmatically change the FROM value. The link below is directly to the API call for setting from but to accomplish it you'd still need to follow the manual tutorial then replace its steps with equivalent API Calls.
http://docs.aws.amazon.com/ses/latest/APIReference/API_SetIdentityMailFromDomain.html

"Read" Emails with Django

Currently sending emails with Django, and was wondering if there was any way to periodically check my inbox with Django (or ideally somehow alert the server upon receipt of a new email), and have Django extract the message and save it in the database.
You could use an email service such as SendMail or Mandrill (latter definitely has free accounts, former may have).
Each of these services provide inbound email support via webhooks. You provide them an endpoint to hit (make sure to use HTTPS) and when they receive an email to an address you have registered they will send the data via HTTP POST to you.
It is then just a simple case of storing this data to the database. There are a number of 3rd party packages that can help you with this:
http://djrill.readthedocs.org/en/v1.4/usage/webhooks/
https://github.com/yunojuno/django-inbound-email
https://github.com/jpadilla/mandrill-inbound-python
https://github.com/michaelhelmick/python-mailsnake
Although it's rather simple to roll your own should need be.

Custom mass mailing with SendGrid

I have requirement to send customised(per user) newsletter to thousands of users.
I created a django app which generates custom newsletter content based on user preference.
I am using SendGrid, and planning to add celery to send newsletter one by one.
Sendgrid docs says:
Customers should utilize SMTPAPI if this is an option. As with SMTP, 100 messages can be sent with each connection, but there can be 1000 recipients for each message.
Is there anything like --- SengGrid collecting all the emails I throw at them, make SMTP connection and send to user.
Otherwise, as every newsletter is unique based on receiver, I will have to make single SMTP connection for each email, which I think won't work in case of thousands of emails.
Or is there any other options?
I would just set yourself up to use their REST API. I have used that to send thousands of emails per day. http://sendgrid.com/docs/API_Reference/Web_API/mail.html
If you are worried about performance then make it into a job with Django Celery