Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- settings.py
- EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
- EMAIL_USE_TLS = True
- EMAIL_HOST='smtp.gmail.com'
- EMAIL_HOST_USER='kumarprosenjit21@gmail.com'
- EMAIL_HOST_PASSWORD='************' # (my gmail password)
- EMAIL_PORT = 587
- views.py
- def send_mass_mail(datatuple=(
- 'subject',
- 'message',
- settings.EMAIL_HOST_USER,
- ['prosenjitearnkumar@gmail.com'])):
- """
- Given a datatuple of (subject, message, from_email, recipient_list), send
- each message to each recipient list. Return the number of emails sent.
- If from_email is None, use the DEFAULT_FROM_EMAIL setting.
- If auth_user and auth_password are set, use them to log in.
- If auth_user is None, use the EMAIL_HOST_USER setting.
- If auth_password is None, use the EMAIL_HOST_PASSWORD setting.
- Note: The API for this method is frozen. New code wanting to extend the
- functionality should use the EmailMessage class directly.
- """
- connection = get_connection(
- username=settings.EMAIL_HOST_USER,
- password=settings.EMAIL_HOST_PASSWORD,
- fail_silently=False,
- )
- messages = [
- EmailMessage(subject, message, sender, recipient)
- for subject, message, sender, recipient in datatuple
- ]
- if connection:
- return HttpResponse(connection.send_messages(messages))
- else:
- return HttpResponse("Connectiom Refused")
- #return HttpResponse(connection.send_messages(messages))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement