add smtp test function
This commit is contained in:
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user