Update main.py
This commit is contained in:
parent
99f92c077b
commit
e369c19822
44
main.py
44
main.py
@ -11,10 +11,10 @@ import os
|
|||||||
def connect_db(sql_query):
|
def connect_db(sql_query):
|
||||||
try:
|
try:
|
||||||
connection = mysql.connector.connect(
|
connection = mysql.connector.connect(
|
||||||
host='192.168.145.196',
|
host='192.168.xxx',
|
||||||
user='sql_to_xlsx',
|
user='xxx',
|
||||||
password='2Uce5Uc5',
|
password='xxx',
|
||||||
database='smsgw_control',
|
database='xxx',
|
||||||
auth_plugin='mysql_native_password',
|
auth_plugin='mysql_native_password',
|
||||||
ssl_disabled=True,
|
ssl_disabled=True,
|
||||||
use_pure=True
|
use_pure=True
|
||||||
@ -43,11 +43,11 @@ def write_to_excel(data, headers, file_name):
|
|||||||
print(f"Excel file saved as {file_name}")
|
print(f"Excel file saved as {file_name}")
|
||||||
|
|
||||||
|
|
||||||
def send_email(subject, body, recipient_email, sender_email, filename, smtp_server, smtp_port, smtp_user, smtp_password):
|
def send_email(subject, body, recipient_emails, sender_email, filename, smtp_server, smtp_port, smtp_user, smtp_password):
|
||||||
try:
|
try:
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
msg['From'] = sender_email
|
msg['From'] = sender_email
|
||||||
msg['To'] = recipient_email
|
msg['To'] = ', '.join(recipient_emails) # Join multiple recipients
|
||||||
msg['Subject'] = subject
|
msg['Subject'] = subject
|
||||||
|
|
||||||
msg.attach(MIMEText(body, 'plain'))
|
msg.attach(MIMEText(body, 'plain'))
|
||||||
@ -82,22 +82,36 @@ FROM
|
|||||||
LEFT JOIN smsgw_control.E212_MCC ON routingprices.mcc = smsgw_control.E212_MCC.MCC
|
LEFT JOIN smsgw_control.E212_MCC ON routingprices.mcc = smsgw_control.E212_MCC.MCC
|
||||||
LEFT JOIN smsgw_control.E212_MCCMNC on routingprices.mcc = smsgw_control.E212_MCCMNC.MCC and routingprices.mnc = smsgw_control.E212_MCCMNC.MNC
|
LEFT JOIN smsgw_control.E212_MCCMNC on routingprices.mcc = smsgw_control.E212_MCCMNC.MCC and routingprices.mnc = smsgw_control.E212_MCCMNC.MNC
|
||||||
WHERE
|
WHERE
|
||||||
route = 'M1' AND clientid = '13283';"""
|
route = 'M1' AND clientid = '';"""
|
||||||
|
|
||||||
results, headers = connect_db(sql_query)
|
results, headers = connect_db(sql_query)
|
||||||
|
|
||||||
excel_file_name = "pricelist.xlsx"
|
excel_file_name = "Mes_Bird_Dir_price_list.xlsx"
|
||||||
write_to_excel(results, headers, excel_file_name)
|
write_to_excel(results, headers, excel_file_name)
|
||||||
|
|
||||||
subject = "Mexedia pricelist"
|
subject = "MEXEDIA PRICE CHANGE for MessageBird- Mes_Bird_Dir"
|
||||||
body = "Please find attached your pricelist"
|
body = """Dear Valued Customer,
|
||||||
recipient_email = "mark@42tele.com"
|
|
||||||
sender_email = "mark@42tele.com"
|
We would like to inform you of the following price changes on your account Mes_Bird_Dir.
|
||||||
|
|
||||||
|
Please note that the changes are effective immediately, any messages sent from now on will be charged based on the new price.
|
||||||
|
If you require any further assistance or clarification, please do not hesitate to contact your Account Manager or our Support Team on support.sms@mexedia.com and we'll gladly assist you further.
|
||||||
|
|
||||||
|
Best Regards,
|
||||||
|
|
||||||
|
Mexedia Customer Support
|
||||||
|
|
||||||
|
Support | support.sms@mexedia.com
|
||||||
|
Sales | sales-sms@mexedia.com
|
||||||
|
www.mexedia.com"""
|
||||||
|
|
||||||
|
recipient_emails = ["xxx@xxx.com", "xxx@xxx.com"]
|
||||||
|
sender_email = "donotreply@xxx.mt"
|
||||||
smtp_server = "smtp.eu.mailgun.org"
|
smtp_server = "smtp.eu.mailgun.org"
|
||||||
smtp_port = 587
|
smtp_port = 587
|
||||||
smtp_user = 'stps@monitoring.fortytwo.mt'
|
smtp_user = 'xxx'
|
||||||
smtp_password = 'f18c48a7076c868bef91eb8f0ca59d33-9776af14-d2648a16'
|
smtp_password = 'xx-xx-xx'
|
||||||
|
|
||||||
send_email(
|
send_email(
|
||||||
subject, body, recipient_email, sender_email, excel_file_name, smtp_server, smtp_port, smtp_user, smtp_password
|
subject, body, recipient_emails, sender_email, excel_file_name, smtp_server, smtp_port, smtp_user, smtp_password
|
||||||
)
|
)
|
||||||
Loading…
Reference in New Issue
Block a user