如何使用Python向特定的手机用户发送消息?

2024-04-25 16:57:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在PostgreSQL和Python之间建立了关系。我提供了向使用Python的用户发送电子邮件的功能。我想向特定用户的手机发送消息。你知道吗

我分享了我的一部分代码:

Enter image description here


Tags: 代码用户image功能消息here关系电子邮件
2条回答

您可以使用Amazon SNS服务(简单通知服务)。它是一个REST服务,因此可以在任何语言中使用,包括Python。你知道吗

参见Using Amazon SNS for User Notifications with a Mobile Phone Number as a Subscriber (Send SMS)。你知道吗

Therearemanyresourcesaround。你知道吗

代码

from smsapi import SmsApi
username = "USERNAME"
password = "PASSWORD"

sms = SmsApi(username, password)

total_points = sms.get_points()['points']
print("You have", total_points, "points left")

cursor = conn.cursor()

list_of_client_numbers = cursor.execute('''SELECT mobNumber FROM clientsTable''')

for eachRecord in list_of_client_numbers:
    sms = sms.send_sms(
          recipient=eachRecord,
          sender_name="YOUR COMPANY NAME",
          message="MESSAGE",
          eco=False)

conn.close()

total_points = sms.get_points()['points'] print("You have", total_points, "points left")

相关问题 更多 >

    热门问题