Jun-10-2024, 01:52 PM
(This post was last modified: Jun-10-2024, 02:28 PM by deanhystad.)
I found out that the issue maybe related to the email headers. Specifically, the Date header wasn't being set correctly in email message, which is why it defaulted to the Unix epoch time.
Here's the updated code that can solve the issue:
python
Copy code
Here's the updated code that can solve the issue:
python
Copy code
import smtplib, ssl from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.utils import formatdate # Load email addresses from JSON or other source customer_emails = ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"] smtp_server = "smtp.qq.com" port = 465 sender_email = "[email protected]" password = "your_password" # Create the email message message = MIMEMultipart() message["From"] = sender_email message["Subject"] = "Test Email" message.attach(MIMEText("This is a test email.", "plain")) message["Date"] = formatdate(localtime=True) context = ssl.create_default_context() with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: server.login(sender_email, password) for e in customer_emails: print(f'email is {e}') server.sendmail(sender_email, e, message.as_string()) print(f'email sent to {e}')Adding the Date header with formatdate(localtime=True) ensures that the current local time is correctly set in the email header.
deanhystad write Jun-10-2024, 02:28 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.