I want to be notify people via SMS when certain things happen. Seems like it should be pretty straighforward. But when the SMS arrives it has the sender and subject line in the message, and I can't figure out how to adjust the message to get rid of it.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
message = MIMEMultipart()
message['From'] = "[email protected]"
message['To'] = "[email protected]"
message['Subject'] = "FOOBAR!"
text = "Hello, world!"
message.attach(MIMEText(text.encode("utf-8"), "plain", "utf-8"))
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(message["From"], "SuperSecretString")
server.sendmail(message["From"], [message["To"]], text)
Produces something like:
[email protected] / FOOBAR!/ Hello, world!
, and all I want to see is Hello, world!
Open Gmail and click on Compose from the Main Menu. 2. In the To field, enter the recipient's 10-digit cell phone number (no country code) followed by “@” and the SMS gateway address textmagic.com. For example, this is how you would send a message to [email protected].
The SMTP (E-mail to SMS) connection can be used to send SMS messages through E-mail to SMS services. E-mail to SMS connectivity is provided by many mobile network operators and multichannel IP based GSM gateways. If you install this connection, you can connect to these services.
After doing a bit of research, it seems that using SMS gateways to send SMS messages is limiting in that you only so much control over the format of your text.
However this modification on the structure of the text being sent works for me on Sprint in the format you want:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
message = MIMEMultipart()
message['From'] = "[email protected]"
message['To'] = "[email protected]"
message['Subject'] = "FOOBAR!"
text = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
% (message['From'], ", ".join(message['To']), message['Subject']) )
text += "Hello World!\r\n"
message.attach(MIMEText(text.encode("utf-8"), "plain", "utf-8"))
server = smtplib.SMTP("smtp.zoho.com", 587)
server.starttls()
server.login(message["From"], "**********")
server.sendmail(message["From"], [message["To"]], text)
Note that I took this message body format from this thread and adapted it to your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With