diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index 81a22aa..8b11f5f 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -203,6 +203,8 @@ def mailing_subscribe_ajax(request): def send_message_ajax(request): + print('send_message_ajax') + if request.method != 'POST': raise Http404 @@ -311,14 +313,18 @@ def send_message_ajax(request): f'

' } + print('render html for mail') + html = render_to_string('mail/m_request_offer.html', Dict, request) from BaseModels.mailSender import admin_send_mail_by_SMTPlib mail_sets = get_mail_send_options() opts = get_options_by_opt_types('support_email', only_vals=True) + print(f'options: {str(opts)}') if opts and 'support_email' in opts: to = [opts['support_email']] else: to = [mail_sets['sender_email']] + print(f'to: {str(to)}') res = admin_send_mail_by_SMTPlib( mail_sets, subject=subject, diff --git a/BaseModels/mailSender.py b/BaseModels/mailSender.py index 2f0fe8e..9bde30e 100644 --- a/BaseModels/mailSender.py +++ b/BaseModels/mailSender.py @@ -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
' + f'{str(traceback.format_exc())}') print(msg) try: mail_lib.quit()