add smtp test function

This commit is contained in:
virusdefender
2017-12-24 11:34:40 +08:00
parent 47da932a2b
commit 872e7407cf
5 changed files with 55 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ from base64 import b64encode
from io import BytesIO
from django.utils.crypto import get_random_string
from envelopes import Envelope
def rand_str(length=32, type="lower_hex"):
@@ -63,3 +64,15 @@ def timestamp2utcstr(value):
def natural_sort_key(s, _nsre=re.compile(r"(\d+)")):
return [int(text) if text.isdigit() else text.lower()
for text in re.split(_nsre, s)]
def send_email(smtp_config, from_name, to_email, to_name, subject, content):
envelope = Envelope(from_addr=(smtp_config["email"], from_name),
to_addr=(to_email, to_name),
subject=subject,
html_body=content)
return envelope.send(smtp_config["server"],
login=smtp_config["email"],
password=smtp_config["password"],
port=smtp_config["port"],
tls=smtp_config["tls"])