command-line - 是否可以通过 Linux 命令行发送 SMS 消息?
问题描述
我需要通过 Linux 命令行向特定的电话号码发送短信。我已经寻找一种方法来做到这一点,但大多数都已经过时,或者看起来像是骗局。
这样的事情仍然可能吗?如果是这样,最好/最便宜的方法是什么?
解决方案
您可以通过在 Linux 命令行中运行 Python 脚本来发送 SMS。
我在这里包含了脚本的 python 代码。
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()
但为此,您需要运营商的 SMS 网关。
详情请看:链接
推荐阅读
- java - 将多个类写入一个 CSV 文件
- java - 覆盖方法和`List时的协变返回类型
'与'列表' - c# - while (true) 中的 C++ 程序意外退出
- javascript - VueJS路由器查看反应道具未定义
- reactjs - URL 不显示当前页面
- java - 在 Gridpane 上获取单元格内容
- django - 将响应发送到客户端(在 PythonAnywhere 上)后,如何在 Django 中执行代码?
- boolean-logic - 如何简化以下表达式
- java - 如何在 Gson 中使用 @SerializableName 编辑日期格式?
- api - 为什么我的 FutureBuilder 不返回任何数据?