options init
This commit is contained in:
SDE
2023-11-29 20:51:36 +03:00
parent 42cf20137b
commit 23de94b8cd
3 changed files with 62 additions and 27 deletions

View File

@@ -82,26 +82,18 @@ def prepare_xls_attach_by_xls_virtual_file(virtual_file, filename):
return file
def admin_send_mail_by_SMTPlib(subject, from_email, to, html_content, attachments=None):
def admin_send_mail_by_SMTPlib(sets, subject, from_email, to, html_content, attachments=None):
res = None
try:
smtp_server = sets['mail_server_url']
smtp_port = sets['mail_server_smtp_port']
smtp_password = sets['sender_mail_password']
smtp_login = sets['sender_mail_login']
res = send_mail_by_SMTPlib(subject, from_email, to, html_content, smtp_server, smtp_port, smtp_login,
smtp_password, attachments)
try:
smtp_server = 'mail.truenergy.by'
smtp_port = 587
smtp_password = 'eg4$#95Xp0T*V%ig5BbR'
smtp_login = 'support@truenergy.by'
res = send_mail_by_SMTPlib(subject, from_email, to, html_content, smtp_server, smtp_port, smtp_login,
smtp_password, attachments)
except:
smtp_server = 'mail.truenergy.by'
smtp_port = 25
smtp_password = 'PowH@aL0a4%$iz0Uo5V$'
smtp_login = 'tech@truenergy.by'
res = send_mail_by_SMTPlib(subject, smtp_login, to, html_content, smtp_server, smtp_port, smtp_login,
smtp_password, attachments)
except Exception as e:
msg = 'admin_send_mail_by_SMTPlib error = {0}'.format(str(e))
@@ -111,7 +103,7 @@ def admin_send_mail_by_SMTPlib(subject, from_email, to, html_content, attachment
return str(res)
def send_mail_by_SMTPlib(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):
to = to_init
if not settings.prod_server:
@@ -153,15 +145,15 @@ def send_mail_by_SMTPlib(subject, from_email, to_init, html_content, smtp_server
res = None
if type(to) in (list, tuple):
if 'support@truenergy.by' in to:
to.remove('support@truenergy.by')
if sets['sender_email'] in to:
to.remove(sets['sender_email'])
if len(to) > 1:
to_str = u', '.join(to)
else:
to_str = to[0]
else:
if to == 'support@truenergy.by':
if to == sets['sender_email']:
return None
to_str = to
to = []
@@ -229,10 +221,10 @@ def send_mail_by_SMTPlib(subject, from_email, to_init, html_content, smtp_server
return msg
def sendMail(subject, text_content, from_email, to, html_content):
def sendMail(sets, subject, text_content, from_email, to, html_content):
print('sendMail to {0}'.format(str(to)))
admin_send_mail_by_SMTPlib(subject, from_email, [to], html_content)
admin_send_mail_by_SMTPlib(sets, subject, from_email, [to], html_content)
# msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
# msg.attach_alternative(html_content, "text/html")
@@ -244,7 +236,7 @@ def sendMail(subject, text_content, from_email, to, html_content):
def techSendMail_for_specified_email_list(html_content, email_list, title=None):
def techSendMail_for_specified_email_list(sets, html_content, email_list, title=None):
try:
print('techSendMail_for_specified_email_list')
@@ -254,7 +246,7 @@ def techSendMail_for_specified_email_list(html_content, email_list, title=None):
subject = u'truEnergy Data техническое оповещение'
from_email = 'support@truenergy.by'
res = admin_send_mail_by_SMTPlib(subject, from_email, email_list, html_content)
res = admin_send_mail_by_SMTPlib(sets, subject, from_email, email_list, html_content)
print(res)
return u'Accept'
@@ -267,7 +259,7 @@ def techSendMail_for_specified_email_list(html_content, email_list, title=None):
return 'Fail'
def techSendMail(html_content, title=None, add_emails=None):
def techSendMail(sets, html_content, title=None, add_emails=None):
# if not prod_server:
# msg = '{0}. Not sended because is local'.format(html_content)
# print(msg)
@@ -288,7 +280,7 @@ def techSendMail(html_content, title=None, add_emails=None):
else:
subject = u'truEnergy Data техническое оповещение'
res = admin_send_mail_by_SMTPlib(subject, from_email, to, html_content)
res = admin_send_mail_by_SMTPlib(sets, subject, from_email, to, html_content)
print(res)

View File

@@ -0,0 +1,27 @@
from .models import *
def get_options_by_opt_types(opt_types, only_vals=False):
if type(opt_types) == str:
kwargs = {'opt_type': opt_types}
elif type(opt_types) == dict:
kwargs = opt_types
else:
kwargs = {'opt_type__in': opt_types}
opts = Option.objects.filter(**kwargs)
if opts and only_vals:
opts = opts.values('name', 'value')
opts = {item['name']: item['value'] for item in opts}
return opts
def get_first_option_value_by_opt_type(opt_type):
opts = get_options_by_opt_types(opt_type)
if opts:
return opts[0].value
else:
return None
def get_mail_send_options():
opt_types = ['mail_server_url', 'mail_server_smtp_port', 'sender_mail_login', 'sender_mail_password', 'sender_email']
return get_options_by_opt_types(opt_types, only_vals=True)

View File

@@ -5,31 +5,47 @@ required_options_Dict = {
'Адрес почтового сервера': {
'name': 'Адрес почтового сервера',
'opt_type': 'mail_server_url',
'value': '213.142.147.40',
},
'SMTP порт почтового сервера': {
'name': 'SMTP порт почтового сервера',
'opt_type': 'mail_server_smtp_port',
'value': 587,
},
'email для отправки писем с сайта': {
'login для отправки писем с сайта': {
'name': 'email для отправки писем с сайта',
'opt_type': 'sender_mail_login',
'value': 'admin@tripwb.com',
},
'email для отправки': {
'name': 'email для отправки',
'opt_type': 'sender_email',
'value': 'admin@tripwb.com',
},
'Пароль для отправки писем с сайта': {
'name': 'пароль для отправки писем с сайта',
'opt_type': 'sender_mail_password',
'value': 't5Fdcah^gdajY',
},
'Название проекта': {
'name': 'Название проекта',
'opt_type': 'project_name',
'value': 'TWB'
'value': 'TWB',
},
'Адрес сайта': {
'name': 'Адрес сайта',
'opt_type': 'domain',
'value': 'tripwb.com',
},
'email техподдержки': {
'name': 'email техподдержки',
'opt_type': 'support_email',
'value': 'admin@tripwb.com',
},
'корпоративный email': {
'name': 'корпоративный email',
'opt_type': 'corp_email',
'value': 'admin@tripwb.com',
},
}