Hi!
I'm having problems connecting to and/or sending email through an SMTP server. I've tried everything Google can find, but I'm clearly not understanding something.
When executing the program below, the code executes with no errors, but everything hangs at the end with a message saying the software unexpectedly lost connection with the server. No messages were sent. Here's the code.
Thanks!
Larry
= = =
I'm having problems connecting to and/or sending email through an SMTP server. I've tried everything Google can find, but I'm clearly not understanding something.
When executing the program below, the code executes with no errors, but everything hangs at the end with a message saying the software unexpectedly lost connection with the server. No messages were sent. Here's the code.
Thanks!
Larry
= = =
# Version 0.5 # import email libraries import smtplib from email.message import EmailMessage # Define variables email_to = '[email protected]' #This is obviously a fake address, but using the real thing doesn't work either. It is properly formatted as a string. email_from = '[email protected]' # Same thing, fake, but the correct address doesn't work - also formatted as a string. email_pw = 'password' # Yup, another string. # Read email body text file - this the text of the email I want to send. All data merges are already stored in this file. It is a pure text file. with open('/Users/larryj/Desktop/temp.txt','r') as file: content=file.read() # Create a text/plain message msg = EmailMessage() msg['Subject'] = 'Thank you ' msg['From'] = email_from msg['To'] = email_to msg.set_content(content) # Content contains the data read from the text file above. # setup the server smtp_server = 'secure.emailsrvr.com' # This is the correct address for Rackspace email smtp_user = email_from # In this case the sender also owns the email account smtp_password = email_pw # Send the message - the dashes are ACTUALLY spaces, which this forum removes. They are spaces in the script. with smtplib.SMTP(smtp_server, 465) as server: #This is the correct port for SMTP messages on Rackspace email server.starttls() # Upgrades the connection to a secure encrypted SSL/TLS connection server.login(smtp_user, smtp_password) server.send_message(msg)
buran write Mar-27-2026, 05:00 AM:
No BBcode Answer
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.
No BBcode Answer
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.
