Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------- Views.py ---------------
- @csrf_exempt
- def counter(request):
- template = "test.html"
- return render(request, template)
- @csrf_exempt
- def enviar_emails(request):
- email = request.POST.get('emails', None)
- segundos = request.POST.get('segundos', 15)
- if not email == None:
- email = str(email).split(',')
- SMTPserver = 'host'
- sender = 'mail'
- USERNAME = "user"
- PASSWORD = "pass"
- # typical values for text_subtype are plain, html, xml
- text_subtype = 'html'
- content="Email"
- subject="Subject"
- import sys
- import os
- import re
- from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
- from email.mime.text import MIMEText
- try:
- msg = MIMEText(content, text_subtype)
- msg['Subject']= subject
- msg['From'] = sender # some SMTP servers will do this automatically, not all
- conn = SMTP(SMTPserver)
- conn.set_debuglevel(False)
- conn.login(USERNAME, PASSWORD)
- try:
- for destination in email:
- conn.sendmail(sender, destination, msg.as_string())
- time.sleep(segundos)
- #return HttpResponse(destination) #Esto rompe todo
- finally:
- conn.quit()
- except Exception as exc:
- sys.exit( "mail failed; %s" % str(exc) )
- return HttpResponse(email)
Add Comment
Please, Sign In to add comment