Custom mass mailing with SendGrid - django

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

Related

"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.

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.

How to send e-mail from Django to more than 10 thousand subscribers without getting out of memory

I am using the basic version of Webfaction server to host my web application written in Python/Django. I am adding newsletter feature. There are more than 10 thosuand subscribers are still growing. How to send the newsletter to each of them. This is what I am doing right now. It can send about 200 emails and get out of memory.
for subscriber in subscribers:
send_email(title, content, 'sender', subscriber)
What's the best way to handle this in a shared hosting server with limited resources.
Thank you
You'll want to use a service for sending out the emails, many benefits that you don't have to build out yourself. That way you can fire off thousands of emails and your Django web server won't have to slow down and handle each email. You'll also get the ability to track bounces and have much more reliable sending.
SendGrid - With django-sendgrid
There are a few other services out there like Postmarkapp

How does one send an email to 10,000 users in Django?

My Django application has 10,000 users, all with emails. I would like to send an email message to all of them say once a month. This message could have some pdf attachments.
What I have tried is using an EmailMessage object to send an email to all of them. I add all users' email addresses to the bcc component of this EmailMessage before sending.
recList = []
for recipient in rec:
reci = str.strip(str(recipient))
recList.append(reci)
message = (form.cleaned_data['subject'], form.cleaned_data['message'], 'emailAdmin#yahoo.com', recList)
mail = EmailMessage(form.cleaned_data['subject'], form.cleaned_data['message'], 'email_manager#mysite.org', ['email_list#mysite.org'], recList)
num_attachments = 0
if form.cleaned_data['attachment'] != None:
email_attachment = EmailAttachment(
document_name = form.cleaned_data['attachment'].name,
email_message = email,
document = form.cleaned_data['attachment'],
)
email_attachment.save()
mail.attach_file(settings.MEDIA_ROOT + "/" + email_attachment.document.name)
mail.send(fail_silently=False)
However, when I send the email, Django complains that "The connection was reset" and does not send. I am assuming that the server connection was closed.
What's an efficient way to send a mass email blast in Django? Would send_mass_mail() be more effective?
You should use send_mass_mail since it won't close the connection every time. docs
I would also chunk the messages into groups of about 100-1,000, depending on how powerful your server is. The reason is that you can catch errors in smaller groups for retrying. This also results in a separate email per recipient, which is ideal. BCC'ing thousands of people is not great.
An alternative suggestion: sign up to a mailing service and use their APIs to maintain your email list and send out mailings. A couple of advantages to this approach:
They’ll handle any unsubscribe requests for you, so you don’t have to worry about adding exclusion flags to your users who don’t want your emails.
You’re less likely to get spam-filtered out of your users’ inboxes, or to annoy your hosting provider.
There are API wrappers available for, among others, MailChimp and Campaign Monitor. It should be fairly easy to add in hooks to add new users to the mailing list and (if relevant) remove any users who delete their accounts.
I think, an E-mail BCC header cannot contain 10000 records.

Custom Email Marketing from Django on Slicehost Server

I have a Slicehost slice running django through nginx and apache. This is for a project in which email marketing is a key component. We will need to be able to send up to 10,000 emails in a day from this Django app. We need to recieve email as well, however, that can simply be a forwarder.
What would be your recommended solution? would you setup a postfix mail server on the slice or try to use some 3rd party mail service with an API like MailChimp or constant contact?
Sending thousands of emails from your own machine in a reliable way is very hard.
I would recommend you to use SendGrid. You can use them as a smtp server, so there's no need to code against APIs. They can also receive email and POST the data to a URL on your server.