20221124授業内容 pythoのcgi mail

20221124授業内容 pythoのcgi mail

You are currently viewing a revision titled "20221124授業内容 pythoのcgi mail", saved on 2022年11月24日 9:15 AM by fittingmind
タイトル
20221124授業内容 pythoのcgi mail
コンテンツ
index.html ------------------- python mail test
name

address

Tel

contents


---------------------- mail.py ---------------------- #!/usr/bin/python3.6 print ('Content-Type: text/html\n\n') import cgi import sys import io #htmlのformからの入力しinputと言う関数に代入########################### form = cgi.FieldStorage() name = form.getvalue('name') add = form.getvalue('add') tel = form.getvalue('tel') bunsyou = form.getvalue('bunsyou') ####################################################################### sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') print("[Python CGI input]",file=sys.stderr) print('Content-Type: text/html; charset=UTF-8\n') ####################################################################### html_header = """ """ contents = """

python mail 見本


入力された内容は

""" html_footer = """
""" ####################################################################### #変数代入されたものをprint############# print(html_header) print(contents) print(name) print("

") print(add) print("

") print(tel) print("

") print(bunsyou) print("
") print(" ") print(" ") print(" ") print(" ") print("") print("") print("
") print("

") print(html_footer) ################################### --------------------- mailsend.py --------------------- #!/usr/bin/python3.6 # -*- coding: utf-8 -*- from email import message import smtplib import ssl import cgi import sys import io from email.mime.text import MIMEText from email.header import Header from email.utils import formatdate ##################################################################### smtp_mode = 'normal' smtp_host = 's309.xrea.com' smtp_account_id = 'teacher@ibaraki-school.net' smtp_account_pass = '1234qwer' from_mail = 'teacher@ibaraki-school.net' to_mail = 'waterspring7@gmail.com' charset = 'ISO-2022-JP' ###################################################################### ####################################################################### sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') print("[Python CGI input]",file=sys.stderr) print('Content-Type: text/html; charset=UTF-8\n') ####################################################################### form = cgi.FieldStorage() name = form.getvalue('name') add = form.getvalue('add') tel = form.getvalue('tel') bunsyou = form.getvalue('bunsyou') #bunsyou = "test" ####################################################################### all = ('お名前:')+(name)+('\n')+('住所:')+(add)+('\n')+('電話:')+(tel)+('\n')+('内容:')+('\n')+(bunsyou)+('\r\n') msg = message.EmailMessage() msg.set_content(all); ####################################################################### msg = MIMEText(all, 'plain', charset) msg['Subject'] = 'pythonメールフォーム' msg['From'] = from_mail msg['To'] = to_mail if smtp_mode == 'starttls': server = smtplib.SMTP(smtp_host, 587, timeout=10) server.ehlo() server.starttls() server.ehlo() elif smtp_mode == 'ssl': context = ssl.create_default_context() server = smtplib.SMTP_SSL(smtp_host, 465, timeout=10, context=context) else: server = smtplib.SMTP(smtp_host, 25, timeout=10) server.login(smtp_account_id, smtp_account_pass) server.send_message(msg) server.quit() ####################################################################### html_header = """ """ contents = """

メール送信完了


おくったよ~

""" html_footer = """
""" ####################################################################### #print('Content-Type: text/html; charset=utf-8') print() print(html_header) print(contents) print(html_footer)
抜粋
脚注


Old New Date Created Author Actions
2022年11月24日 12:15 AM fittingmind

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です