Guest User

Untitled

a guest
Dec 10th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. class Configuration(models.Model):
  2. email_use_tls = models.BooleanField(_(u'EMAIL_USE_TLS'),default=True)
  3. email_host = models.CharField(_(u'EMAIL_HOST'),max_length=1024)
  4. email_host_user = models.CharField(_(u'EMAIL_HOST_USER'),max_length=255)
  5. email_host_password = models.CharField(_(u'EMAIL_HOST_PASSWORD'),max_length=255)
  6. email_port = models.PositiveSmallIntegerField(_(u'EMAIL_PORT'),default=587)
  7. ....
  8.  
  9. from django.core.mail import EmailMessage
  10. from django.core.mail.backends.smtp import EmailBackend
  11.  
  12.  
  13. config = Configuration.objects.get(**lookup_kwargs)
  14.  
  15. backend = EmailBackend(host=config.host, port=congig.port, username=config.username,
  16. password=config.password, use_tls=config.use_tls, fail_silently=config.fail_silently)
  17.  
  18. email = EmailMessage(subject='subj', body='body', from_email=from_email, to=to,
  19. connection=backend)
  20.  
  21. email.send()
  22.  
  23. backend = EmailBackend(host=config.host, port=congig.port, username=config.username,
  24. password=config.password, use_tls=config.use_tls, fail_silently=config.fail_silently)
  25. email = EmailMessage(subject='subj', body='body', from_email=from_email, to=to,
  26. connection=backend)
  27.  
  28. $ pip install django-des
  29.  
  30. INSTALLED_APPS = (
  31. ...
  32. 'django_des',
  33. ...
  34. )
  35.  
  36. EMAIL_BACKEND = 'django_des.backends.ConfiguredEmailBackend'
  37.  
  38. from django_des import urls as django_des_urls
  39.  
  40. urlpatterns = [
  41. ...
  42. url(r'^django-des/', include(django_des_urls)),
  43. ]
Add Comment
Please, Sign In to add comment