Форум сайта python.su
Для отправки email,скрипт выбирает файл из шаблона 1. Gotovyj Shablon как сюда добавить опцию отправки в виде HTML,
option1 = raw_input(setprompt(["1"], "")) if option1 == '1' or option1 == '2': print (""" Do you want to use a predefined template or craft a one time email template. 1. Gotovyj Shablon 2. Odnorazovoe Ispol'zovanie Email Template """) template_choice = raw_input(setprompt(["1"], "")) # if predefined template go here if template_choice == '1': # set path for path = 'src/templates/' filewrite=file(setdir + "/email.templates", "w") counter=0 # Pull all files in the templates directory for infile in glob.glob(os.path.join(path, '*.template')): infile=infile.split("/") # grab just the filename infile=infile[2] counter=counter+1 # put it in a format we can use later in a file filewrite.write(infile+" "+str(counter)+"\n") # close the file filewrite.close() # read in formatted filenames fileread=file(setdir + "/email.templates","r").readlines() print_info("Available templates:") for line in fileread: line=line.rstrip() line=line.split(" ") filename=line[0] # read in file fileread2=file("src/templates/%s" % (filename),"r").readlines() for line2 in fileread2: match=re.search("SUBJECT=", line2) if match: line2=line2.rstrip() line2=line2.split("=") line2=line2[1] # strip double quotes line2=line2.replace('"', "") # display results back print line[1]+": "+line2 # allow user to select template choice=raw_input(setprompt(["1"], "")) for line in fileread: # split based off of space line=line.split(" ") # search for the choice match=re.search(str(choice), line[1]) if match: # print line[0] extract=line[0] fileopen=file("src/templates/"+str(extract), "r").readlines() for line2 in fileopen: match2=re.search("SUBJECT=", line2) if match2: subject=line2.replace('"', "") subject=subject.split("=") subject=subject[1] match3=re.search("BODY=", line2) if match3: body=line2.replace('"', "") body=body.replace(r'\n', " \n ") body=body.split("=") body=body[1] if template_choice == '2' or template_choice == '': subject=raw_input(setprompt(["1"], "Subject of the email")) try: html_flag=raw_input(setprompt(["1"], "Send the message as html or plain? 'h' or 'p' [p]")) if html_flag == "" or html_flag == "p": message_flag="plain" if html_flag == "h": message_flag="html" body = "" body=raw_input(setprompt(["1"], "Enter the body of the message, hit return for a new line. Control+c when finished")) while 1: try: body+=("\n") body+=raw_input("Next line of the body: ") except KeyboardInterrupt: break except KeyboardInterrupt: pass
Отредактировано iNdexoiD (Май 26, 2015 12:07:34)
Офлайн
видя это
print (""" Do you want to use a predefined template or craft a one time email template. 1. Gotovyj Shablon 2. Odnorazovoe Ispol'zovanie Email Template """)
Офлайн