是否可以通过 Linux 命令行发送短信?
Is it possible to send SMS messages via Linux command-line?
我需要通过 Linux 命令行向特定的 phone 号码发送短信。我已经搜索过这样做的方法,但大多数都已过时,或者看起来像是骗局。
这样的事情是否仍然可能,如果可以,best/cheapest 的方法是什么?
您可以通过 运行 Python Linux Command-line 中的脚本发送短信。
我在此处包含了脚本的 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
我需要通过 Linux 命令行向特定的 phone 号码发送短信。我已经搜索过这样做的方法,但大多数都已过时,或者看起来像是骗局。
这样的事情是否仍然可能,如果可以,best/cheapest 的方法是什么?
您可以通过 运行 Python Linux Command-line 中的脚本发送短信。
我在此处包含了脚本的 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