python - 如何删除以短信形式发送的“[Attachment(s) removed]”字符串?
问题描述
我找到了一个小程序,可以通过我的 gmail 向我的手机发送短信,但是当我发送它添加到“[附件已删除]”的文本时,有什么办法可以删除它吗?
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()
解决方案
当您执行 server.sendmail 步骤时,只需发送正文字符串。因此,它将是:
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()
推荐阅读
- ios - 将数据从 Collection View Cell 传递到 View Controller
- javascript - 根据可编辑 DevExpress 表中的其他值设置单元格值
- javascript - Chrome 扩展 - 注入脚本并在非活动选项卡上运行它
- javascript - 如何在 AJAX 查询结果出现之前暂停 HTML 和 JavaScript 文档加载?
- asp.net-mvc - 如何调用位于“Views/Home/Login/Login.cshtml”上的视图?
- python - Pandas 对聚合 min 和 max 的分组速度极慢
- postgresql - 将 PostgreSQL 数据目录更改为 PostgresSQL 在另一台机器上创建的目录
- python - geopy 不会为加拿大邮政编码返回正确的坐标
- excel - 有没有办法在用户窗体上嵌套相关的组合框?
- c - 在 Netfilter 中分配更多有效负载空间的正确方法?