daily pastebin goal
1%
SHARE
TWEET

Untitled

prosenjit1994 Jul 11th, 2018 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. settings.py
  2.  
  3. EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  4. EMAIL_USE_TLS = True
  5. EMAIL_HOST='smtp.gmail.com'
  6. EMAIL_HOST_USER='kumarprosenjit21@gmail.com'
  7. EMAIL_HOST_PASSWORD='************' # (my gmail password)
  8. EMAIL_PORT = 587
  9.  
  10. views.py
  11.  
  12. def send_mass_mail(datatuple=(
  13.         'subject',
  14.         'message',
  15.         settings.EMAIL_HOST_USER,
  16.         ['prosenjitearnkumar@gmail.com'])):
  17.     """
  18.     Given a datatuple of (subject, message, from_email, recipient_list), send
  19.     each message to each recipient list. Return the number of emails sent.
  20.  
  21.     If from_email is None, use the DEFAULT_FROM_EMAIL setting.
  22.     If auth_user and auth_password are set, use them to log in.
  23.     If auth_user is None, use the EMAIL_HOST_USER setting.
  24.     If auth_password is None, use the EMAIL_HOST_PASSWORD setting.
  25.  
  26.     Note: The API for this method is frozen. New code wanting to extend the
  27.     functionality should use the EmailMessage class directly.
  28.     """
  29.     connection = get_connection(
  30.         username=settings.EMAIL_HOST_USER,
  31.         password=settings.EMAIL_HOST_PASSWORD,
  32.         fail_silently=False,
  33.     )
  34.     messages = [
  35.         EmailMessage(subject, message, sender, recipient)
  36.         for subject, message, sender, recipient in datatuple
  37.     ]
  38.     if connection:
  39.         return HttpResponse(connection.send_messages(messages))
  40.     else:
  41.         return HttpResponse("Connectiom Refused")
  42.  
  43.     #return HttpResponse(connection.send_messages(messages))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top