Advertisement
ziibii88

Django send_email

Dec 15th, 2018
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. # imports
  2. from django.core import mail
  3. from django.core.mail.backends.smtp import EmailBackend
  4.  
  5. def email_on_submit(response):
  6.     email_backend = EmailBackend(host='smtp.gmail.com',port='587',username='you@gmail.com',password='passwd',use_tls=True)
  7.     email_connection = mail.get_connection(backend=email_backend, fail_silently=True)
  8.     email_connection.open() # open email connection
  9.     email_message = mail.EmailMessage(
  10.         'Hello',
  11.         'Body goes here',
  12.         'you@gmail.com',
  13.         ['him@gmail.com'],
  14.         connection=email_connection,
  15.     )
  16.     email_message.send() # send the email message
  17.     email_connection.close() # close the email connection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement