Python Forum

Full Version: Sending a text from Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My cell phone is on the U.S. carrier Verizon - and I can send a text to myself by emailing [email protected], where the letters are the placeholder is my phone number.

I am trying to create a python script that upon execution will send a text to my number. My script is below, with sample instead of my real info:

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

message = MIMEMultipart()
message["From"] = "[email protected]"
message["To"] = "[email protected]"
message["Subject"] = "Python Script Completion"
message.attach(MIMEText("test test", "plain"))

try:
    # Create a secure SSL context
    server = smtplib.SMTP("test.com", 587)
    server.starttls()  # Secure the connection
    server.login(message["From"], "PASSWORD")
    # Send the email
    server.sendmail(message["From"], message["To"], message.as_string())
    print("Completion email sent to", message["To"])
except Exception as e:
    # Print any error messages to stdout
    print(e)
finally:
    server.quit()
My webserver setup is a standard cpanel webserver running on linux. I have email services running there like normal.

My script also works to send email, I can get it without issue.

However, when I sent to @vtext.com from the python script, it never makes it. Now, if I login to webmail with the same email as in the python script and send to @vtext.com, the text goes through. But not python.

I suspect it's probably some anti-spam stuff in the email headers. The webmail interface is likely sending that to @vtext.com, but the python script is not. Any ideas to what the solution may be?
Yes, this is definitely some sort of anti-spam thing. I got bounceback emails in my mailbox that the email was blocked. But it didn't offer clues how to fix...
Turns out I was missing a message ID header - I added that in and it's going through now!