Update main.py

This commit is contained in:
Mark 2025-01-28 01:18:42 +01:00
parent 99f92c077b
commit e369c19822

44
main.py
View File

@ -11,10 +11,10 @@ import os
def connect_db(sql_query):
try:
connection = mysql.connector.connect(
host='192.168.145.196',
user='sql_to_xlsx',
password='2Uce5Uc5',
database='smsgw_control',
host='192.168.xxx',
user='xxx',
password='xxx',
database='xxx',
auth_plugin='mysql_native_password',
ssl_disabled=True,
use_pure=True
@ -43,11 +43,11 @@ def write_to_excel(data, headers, 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:
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = recipient_email
msg['To'] = ', '.join(recipient_emails) # Join multiple recipients
msg['Subject'] = subject
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_MCCMNC on routingprices.mcc = smsgw_control.E212_MCCMNC.MCC and routingprices.mnc = smsgw_control.E212_MCCMNC.MNC
WHERE
route = 'M1' AND clientid = '13283';"""
route = 'M1' AND clientid = '';"""
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)
subject = "Mexedia pricelist"
body = "Please find attached your pricelist"
recipient_email = "mark@42tele.com"
sender_email = "mark@42tele.com"
subject = "MEXEDIA PRICE CHANGE for MessageBird- Mes_Bird_Dir"
body = """Dear Valued Customer,
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_port = 587
smtp_user = 'stps@monitoring.fortytwo.mt'
smtp_password = 'f18c48a7076c868bef91eb8f0ca59d33-9776af14-d2648a16'
smtp_user = 'xxx'
smtp_password = 'xx-xx-xx'
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
)