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.
Related
Review Board documentation mentions that
Sender Headers
Review Board can send e-mail on behalf of users. This may happen when creating a new review request or reviewing some code.
E-mails appear to be sent from the users, rather than from Review Board itself.
...
By using these two fields instead of just faking the From address, we can avoid e-mails appearing to be spam or otherwise malicious. Many modern e-mail clients warn if the From address appears to be suspicious.
Is there any way to disable email sending on behalf of users? I want to send emails from default email which is set in the admin panel.
Try setting the from_email in
https://github.com/reviewboard/reviewboard/blob/0935f8daf9b2f07d1f679a1cbed49998df3d59de/reviewboard/notifications/email.py
for the method:
def send_review_mail(user, review_request, subject, in_reply_to,
to_field, cc_field, text_template_name,
html_template_name, context=None, extra_headers=None)
In particular, the line:
from_email = get_email_address_for_user(user)
We do something similar for our server setup at the company to force the sender to be a particular user that we want users to respond to.
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.
Say I've an email id xxx#gmail.com and I get a new mail, I want to send that new mail received instantly to multiple people say yyy#gmail.com , zzz#gmail.com, etc. Is there any script or something that I could use?
http://techietalkz.com/2011/12/07/how-to-auto-forward-incoming-emails-in-gmail-to-multiple-recipients/
and
https://webapps.stackexchange.com/questions/50372/auto-forwarding-emails-to-2-email-addresses
I think you'll need to login to the forwarding e-mail addresses in order to verify you're not just sending out unwanted spam, though.
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
How can i get django send_mail result of email send. I run it local, i do send_mail to my email, and it return True, but letter not sended (because i have not any smtp set). But result is True. How to get real result?
Django uses exceptions to handle email sending problems. The value returned by send_mail is the number of emails that were sent.
If you're not getting an exception, it could be one of a number of things:
You have fail_silently set to True (default is False)
You're using a different email backend (smtp is the default for 1.2+, the only option for earlier versions)
The mail is actually being sent, but something else is wrong (email server, bad email address, spam folders, gmail self-sent mail hiding etc)
Use django-mailer. It puts the emails in the database and uses a cron-jobbed management command to send it out. It will help you track this issue down, improve your app response time, and also make your life easier.
I would also suggest to use exceptions to find out whether email was sent or not.
If you haven't time or option to set up an email server I would suggest to use django+gmail. U can create a 'fake' gmail account (create another one if you already own gmail-acc, it could be 'baned') and use its SMTP as a opportunity to send emails, even if you're working with django's development server (localy). How to is here