2.1.29 check problem send mail
This commit is contained in:
@@ -203,6 +203,8 @@ def mailing_subscribe_ajax(request):
|
|||||||
|
|
||||||
|
|
||||||
def send_message_ajax(request):
|
def send_message_ajax(request):
|
||||||
|
print('send_message_ajax')
|
||||||
|
|
||||||
if request.method != 'POST':
|
if request.method != 'POST':
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
@@ -311,14 +313,18 @@ def send_message_ajax(request):
|
|||||||
f'</p>'
|
f'</p>'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print('render html for mail')
|
||||||
|
|
||||||
html = render_to_string('mail/m_request_offer.html', Dict, request)
|
html = render_to_string('mail/m_request_offer.html', Dict, request)
|
||||||
from BaseModels.mailSender import admin_send_mail_by_SMTPlib
|
from BaseModels.mailSender import admin_send_mail_by_SMTPlib
|
||||||
mail_sets = get_mail_send_options()
|
mail_sets = get_mail_send_options()
|
||||||
opts = get_options_by_opt_types('support_email', only_vals=True)
|
opts = get_options_by_opt_types('support_email', only_vals=True)
|
||||||
|
print(f'options: {str(opts)}')
|
||||||
if opts and 'support_email' in opts:
|
if opts and 'support_email' in opts:
|
||||||
to = [opts['support_email']]
|
to = [opts['support_email']]
|
||||||
else:
|
else:
|
||||||
to = [mail_sets['sender_email']]
|
to = [mail_sets['sender_email']]
|
||||||
|
print(f'to: {str(to)}')
|
||||||
res = admin_send_mail_by_SMTPlib(
|
res = admin_send_mail_by_SMTPlib(
|
||||||
mail_sets,
|
mail_sets,
|
||||||
subject=subject,
|
subject=subject,
|
||||||
|
|||||||
@@ -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,
|
def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_server, smtp_port, smtp_login, smtp_password,
|
||||||
attachments=None):
|
attachments=None):
|
||||||
|
print('send_mail_by_SMTPlib')
|
||||||
to = to_init
|
to = to_init
|
||||||
# if not settings.prod_server:
|
# if not settings.prod_server:
|
||||||
# to = 'web@syncsystems.net'
|
# to = 'web@syncsystems.net'
|
||||||
@@ -123,8 +124,12 @@ def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_
|
|||||||
try:
|
try:
|
||||||
# context = ssl.create_default_context()
|
# context = ssl.create_default_context()
|
||||||
|
|
||||||
|
print('connect to mail server')
|
||||||
|
|
||||||
mail_lib = smtplib.SMTP(smtp_server, smtp_port)
|
mail_lib = smtplib.SMTP(smtp_server, smtp_port)
|
||||||
|
|
||||||
|
print('connection established')
|
||||||
|
|
||||||
res = mail_lib.ehlo()
|
res = mail_lib.ehlo()
|
||||||
|
|
||||||
res = mail_lib.starttls() # context=context)
|
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'
|
res = mail_lib.esmtp_features['auth'] = 'LOGIN PLAIN'
|
||||||
# print('mail_lib.esmtp_features = {0}'.format(str(res)))
|
# print('mail_lib.esmtp_features = {0}'.format(str(res)))
|
||||||
|
|
||||||
|
print('try to login')
|
||||||
|
|
||||||
res = mail_lib.login(smtp_login, smtp_password)
|
res = mail_lib.login(smtp_login, smtp_password)
|
||||||
# print('mail_lib.login = {0}'.format(str(res)))
|
# print('mail_lib.login = {0}'.format(str(res)))
|
||||||
|
|
||||||
|
print('login')
|
||||||
|
|
||||||
res = None
|
res = None
|
||||||
|
|
||||||
if type(to) in (list, tuple):
|
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 = []
|
||||||
to.append(to_str)
|
to.append(to_str)
|
||||||
|
|
||||||
|
print(f'send mail to {str(to)}')
|
||||||
|
|
||||||
if type(subject) != str:
|
if type(subject) != str:
|
||||||
try:
|
try:
|
||||||
subject = subject.decode('utf-8')
|
subject = subject.decode('utf-8')
|
||||||
@@ -168,6 +179,8 @@ def send_mail_by_SMTPlib(sets, subject, from_email, to_init, html_content, smtp_
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
print(f'add context')
|
||||||
|
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
from email.headerregistry import Address
|
from email.headerregistry import Address
|
||||||
msg['From'] = from_email
|
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)
|
res = msg.attach(attachments)
|
||||||
# print('else attach file complete = {0}'.format(str(res)))
|
# print('else attach file complete = {0}'.format(str(res)))
|
||||||
|
|
||||||
|
print(f'send mail')
|
||||||
|
|
||||||
res = mail_lib.sendmail(from_email, to, msg.as_string())
|
res = mail_lib.sendmail(from_email, to, msg.as_string())
|
||||||
|
|
||||||
msg = mail_lib.quit()
|
msg = mail_lib.quit()
|
||||||
# print('mail_lib.quit = {0}'.format(str(msg)))
|
# print('mail_lib.quit = {0}'.format(str(msg)))
|
||||||
|
|
||||||
except Exception as e:
|
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)
|
print(msg)
|
||||||
try:
|
try:
|
||||||
mail_lib.quit()
|
mail_lib.quit()
|
||||||
|
|||||||
Reference in New Issue
Block a user