Guest User

Untitled

a guest
Jul 4th, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. ------- Views.py ---------------
  2. @csrf_exempt
  3. def counter(request):
  4. template = "test.html"
  5. return render(request, template)
  6.  
  7. @csrf_exempt
  8. def enviar_emails(request):
  9. email = request.POST.get('emails', None)
  10. segundos = request.POST.get('segundos', 15)
  11. if not email == None:
  12. email = str(email).split(',')
  13. SMTPserver = 'host'
  14. sender = 'mail'
  15.  
  16. USERNAME = "user"
  17. PASSWORD = "pass"
  18.  
  19. # typical values for text_subtype are plain, html, xml
  20. text_subtype = 'html'
  21.  
  22.  
  23. content="Email"
  24.  
  25. subject="Subject"
  26.  
  27. import sys
  28. import os
  29. import re
  30.  
  31. from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
  32.  
  33. from email.mime.text import MIMEText
  34.  
  35. try:
  36. msg = MIMEText(content, text_subtype)
  37. msg['Subject']= subject
  38. msg['From'] = sender # some SMTP servers will do this automatically, not all
  39.  
  40. conn = SMTP(SMTPserver)
  41. conn.set_debuglevel(False)
  42. conn.login(USERNAME, PASSWORD)
  43. try:
  44. for destination in email:
  45. conn.sendmail(sender, destination, msg.as_string())
  46. time.sleep(segundos)
  47. #return HttpResponse(destination) #Esto rompe todo
  48. finally:
  49. conn.quit()
  50.  
  51. except Exception as exc:
  52. sys.exit( "mail failed; %s" % str(exc) )
  53.  
  54. return HttpResponse(email)
Add Comment
Please, Sign In to add comment