Browse Source

이메일 기능 추가

잉여개발기 (SPDV) 5 years ago
parent
commit
a02734e9db
3 changed files with 18 additions and 7 deletions
  1. 1 4
      route/api_sitemap.py
  2. 16 2
      route/tool/func.py
  3. 1 1
      version.json

+ 1 - 4
route/api_sitemap.py

@@ -8,14 +8,11 @@ def api_sitemap_2(conn):
             '<?xml version="1.0" encoding="UTF-8"?>\n' + \
             '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
         ''
+        domain = load_domain()
 
         curs.execute(db_change("select title from data"))
         all_data = curs.fetchall()
 
-        curs.execute(db_change("select data from other where name = 'domain'"))
-        domain = curs.fetchall()
-        domain = domain[0][0] if domain and domain[0][0] != '' else flask.request.host_url
-
         len_all_data = len(all_data)
         count = int(len_all_data / 30000)
         other_count = len_all_data % 30000

+ 16 - 2
route/tool/func.py

@@ -13,6 +13,8 @@ for i in range(0, 2):
         import tornado.wsgi
         import urllib.request
         import email.mime.text
+        import email.utils
+        import email.header
         import requests
         import sqlite3
         import pymysql
@@ -109,16 +111,21 @@ def send_email(who, title, data):
             elif smtp_security == 'starttls':
                 smtp = smtplib.SMTP(smtp_server, smtp_port)
                 smtp.starttls()
-            else: # if smtp_security == 'tls':
+            else:
+                # if smtp_security == 'tls':
                 smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
             
             smtp.login(smtp_email, smtp_pass)
         else:
             raise
 
+        domain = load_domain()
+
         msg = email.mime.text.MIMEText(data)
         msg['Subject'] = title
-        smtp.sendmail(smtp_email, who, msg.as_string())
+        msg['From'] = email.utils.formataddr((str(email.header.Header(wiki_set()[0], 'utf-8')), 'noreply@' + domain))
+        msg['To'] = who
+        smtp.sendmail('noreply@' + domain, who, msg.as_string())
 
         smtp.quit()
 
@@ -130,6 +137,13 @@ def send_email(who, title, data):
 
         return 0
 
+def load_domain():
+    curs.execute(db_change("select data from other where name = 'domain'"))
+    domain = curs.fetchall()
+    domain = domain[0][0] if domain and domain[0][0] != '' else flask.request.host_url
+
+    return domain
+
 def last_change(data):
     json_address = re.sub(r"(((?!\.|\/).)+)\.html$", "set.json", skin_check())
     try:

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.2.0-stable-13 (beta-37) (dev-2020-09-26-01)",
+        "r_ver" : "v3.2.0-stable-13 (beta-38) (dev-2020-09-27-01)",
         "c_ver" : "3203400",
         "s_ver" : "10"
     }