3

I found a small program that will send my phone a text message through my gmail, but when I send the text it adds on "[Attachment(s) removed]", is there any way to remove that?

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

email = "Your Email"
pas = "Your Pass"

sms_gateway = 'number@tmomail.net'
# The server we use to send emails in our case it will be gmail but every email provider has a different smtp 
# and port is also provided by the email provider.
smtp = "smtp.gmail.com" 
port = 587
# This will start our email server
server = smtplib.SMTP(smtp,port)
# Starting the server
server.starttls()
# Now we need to login
server.login(email,pas)

# Now we use the MIME module to structure our message.
msg = MIMEMultipart()
msg['From'] = email
msg['To'] = sms_gateway
# Make sure you add a new line in the subject
msg['Subject'] = "You can insert anything\n"
# Make sure you also add new lines to your body
body = "You can insert message here\n"
# and then attach that body furthermore you can also send html content.
msg.attach(MIMEText(body, 'plain'))

sms = msg.as_string()

server.sendmail(email,sms_gateway,sms)

# lastly quit the server
server.quit()
Rspitzy
  • 31
  • 6
  • My guess is that is being added by GMail and not by any Python module. – accdias Dec 02 '19 at 19:06
  • Couple of questions. 1.Does this send actually you an email first? 2. How can I replicate the sms part of it? I dont get an email nor sms, login to gmail is successful, and after successful execution I get this message: Process finished with exit code 0 – mdabdullah Dec 02 '19 at 20:05
  • It uses my gmail to send out a message to a phone. To replicate the sms for your own phone you would have sms_gateway = 'yourphonenumber@whatevergatewayyouneedforyourcarrier' https://dev.to/mraza007/sending-sms-using-python-jkd – Rspitzy Dec 02 '19 at 21:41

1 Answers1

5

When you are doing the server.sendmail step just send the body string. So instead it would be:

import smtplib 

email = "Your Email"
pas = "Your Pass"

sms_gateway = 'number@tmomail.net'
smtp = "smtp.gmail.com" 
port = 587
# This will start our email server
server = smtplib.SMTP(smtp,port)
# Starting the server
server.starttls()
# Now we need to login
server.login(email,pas)

body = "Yo, im done."

server.sendmail(email,sms_gateway,body)

# lastly quit the server
server.quit()
Achillean
  • 51
  • 1
  • 4
  • This isn't working for me for some reason. I literally just replace the last part of `sendmail` with the body and it doesn't work but then switch it back to what it was and it works again. – Hercislife Jul 28 '21 at 21:30