2.1.29 check problem send mail
This commit is contained in:
@@ -105,6 +105,7 @@ def admin_send_mail_by_SMTPlib(sets, subject, from_email, to, html_content, atta
|
||||
|
||||
def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_server, smtp_port, smtp_login, smtp_password,
|
||||
attachments=None):
|
||||
print('send_mail_by_SMTPlib')
|
||||
to = to_init
|
||||
# if not settings.prod_server:
|
||||
# to = 'web@syncsystems.net'
|
||||
@@ -123,8 +124,12 @@ def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_
|
||||
try:
|
||||
# context = ssl.create_default_context()
|
||||
|
||||
print('connect to mail server')
|
||||
|
||||
mail_lib = smtplib.SMTP(smtp_server, smtp_port)
|
||||
|
||||
print('connection established')
|
||||
|
||||
res = mail_lib.ehlo()
|
||||
|
||||
res = mail_lib.starttls() # context=context)
|
||||
@@ -139,9 +144,13 @@ def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_
|
||||
res = mail_lib.esmtp_features['auth'] = 'LOGIN PLAIN'
|
||||
# print('mail_lib.esmtp_features = {0}'.format(str(res)))
|
||||
|
||||
print('try to login')
|
||||
|
||||
res = mail_lib.login(smtp_login, smtp_password)
|
||||
# print('mail_lib.login = {0}'.format(str(res)))
|
||||
|
||||
print('login')
|
||||
|
||||
res = None
|
||||
|
||||
if type(to) in (list, tuple):
|
||||
@@ -159,6 +168,8 @@ def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_
|
||||
to = []
|
||||
to.append(to_str)
|
||||
|
||||
print(f'send mail to {str(to)}')
|
||||
|
||||
if type(subject) != str:
|
||||
try:
|
||||
subject = subject.decode('utf-8')
|
||||
@@ -168,6 +179,8 @@ def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_
|
||||
except:
|
||||
pass
|
||||
|
||||
print(f'add context')
|
||||
|
||||
msg = MIMEMultipart()
|
||||
from email.headerregistry import Address
|
||||
msg['From'] = from_email
|
||||
@@ -192,13 +205,17 @@ def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_
|
||||
res = msg.attach(attachments)
|
||||
# print('else attach file complete = {0}'.format(str(res)))
|
||||
|
||||
print(f'send mail')
|
||||
|
||||
res = mail_lib.sendmail(from_email, to, msg.as_string())
|
||||
|
||||
msg = mail_lib.quit()
|
||||
# print('mail_lib.quit = {0}'.format(str(msg)))
|
||||
|
||||
except Exception as e:
|
||||
msg = 'send_mail_by_SMTPlib error = {0}'.format(str(e))
|
||||
import traceback
|
||||
msg = (f'send_mail_by_SMTPlib error = {str(e)}\n<br>'
|
||||
f'{str(traceback.format_exc())}')
|
||||
print(msg)
|
||||
try:
|
||||
mail_lib.quit()
|
||||
|
||||
Reference in New Issue
Block a user