【问题标题】:Is it possible to send SMS messages via Linux command-line? [closed]是否可以通过 Linux 命令行发送 SMS 消息? [关闭]
【发布时间】:2019-06-09 03:51:28
【问题描述】:

我需要通过 Linux 命令行向特定电话号码发送短信。我已经寻找了一种方法来做到这一点,但大多数都已经过时了,或者看起来像是骗局。

这样的事情还有可能吗?如果可以,最好/最便宜的方法是什么?

【问题讨论】:

  • 您可以向该号码发送电子邮件,例如mail -s "out of space" 8887776541@messaging.sprintpcs.com <<< "$more_msg_var",但您必须为每个电话号码的每个运营商找到正确的域。不确定我的示例域是否正确。我无权访问前雇主代码。您可能还必须尝试使用​​您的mail 客户端来消除额外的标头类型数据泄漏。像这样的请求对于 S.O. 来说确实是题外话。请在此处询问更多问题之前阅读Help On-topic。祝你好运。

标签: command-line sms messaging


【解决方案1】:

您可以通过在 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()

但为此您需要运营商的短信网关。

详情请看:Link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 2010-09-05
    • 2015-12-10
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 2021-07-29
    相关资源
    最近更新 更多