问题描述
我已经能够使用以下代码将SMS发送到电话号码
import smpplib
import settings
import sys
client = smpplib.client.Client(settings.SMS_SYSTEM_HOSTNAME,settings.SMS_SYSTEM_PORT)
# Print when obtain message_id
client.set_message_sent_handler(
lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence,pdu.message_id)))
client.set_message_received_handler(
lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))
client.connect()
client.bind_transceiver(system_id=settings.SMS_SYSTEM_ID,password=settings.SMS_SYSTEM_PASSWORD)
pdu = client.send_message(
source_addr_ton=smpplib.consts.SMPP_TON_INTL,#source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,# Make sure it is a byte string,not unicode:
source_addr='SENDER',dest_addr_ton=smpplib.consts.SMPP_TON_INTL,#dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,# Make sure thease two params are byte strings,not unicode:
destination_addr='90474xxxxx',short_message=b'Test message')
print(pdu.sequence)
client.listen()
但是该项目的主要目的是一次发送大量邮件(至少一百万个)。我该怎么办?
显而易见的解决方案可能是放置
pdu = client.send_message(
source_addr_ton=smpplib.consts.SMPP_TON_INTL,not unicode:
destination_addr='904xxxxxxxx',short_message=b'Test message')
是一个循环,但是我对此表示怀疑。是否有更好,更有效的方法来使用Python和SMPP发送批量SMS?