为什么这个python脚本不适用于AT&t用户?

2024-05-16 05:34:37 发布

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

我已经写了一个基本的短信发送python脚本作为一种实践形式。它似乎适用于除AT&T以外的所有主要运营商。值得注意的是,它不会返回错误。有什么建议吗?你知道吗

import smtplib
import sys

print """
Instructions:

Type the cellphone number in without symbols.
Then select one of the following messages to send
by entering the number preceding the message:

1. Your prescription is ready. Call *xxx-xxx-xxxx*
   with any questions.
2. Your prescription was attempted to be filled
   to early. Call *xxx-xxx-xxxx* with any questions.
3. Your prescription needs your Doctor's approval.
   Call *xxx-xxx-xxxx* with any questions.
"""
#gets the number and mess from user                     
number = raw_input('Cellphone Number: ')
message = raw_input('Select Message: ')

#tests to see if a 10 digit number was given 
num_test = True
while num_test == True:
    int(number)
    if len(number) == 10:
        num_test = False 
    else:
        print "The cellphone number you typed in isn't formatted correctly. Try again."
        number = raw_input('Cellphone Number: ')

#cat's number with the major mobile carrier emails 
prov_number_att = number + '@txt.att.net'
prov_number_tmo = number + '@tmomail.net'
prov_number_cin = number + '@cingularme.com'
prov_number_ver = number + '@vmobil.com'
prov_number_sprint = number + '@messaging.sprintpcs.com'
prov_number_next = number + '@messaging.nextel.com'
prov_number_alltel = number + '@message.alltel.com'
prov_number_sun = number + '@tms.suncom.com'
prov_number_vs = number + '@voicestream.net'

#combines these variables into a list so it can be iterated upon
prov_list = [prov_number_att, prov_number_tmo, prov_number_cin, prov_number_ver,
prov_number_sprint, prov_number_next, prov_number_alltel, prov_number_sun, prov_number_vs]

#securely connects to gmail's SMTP (Simple Mail Transfer Protocol) outgoing server 
server = smtplib.SMTP("smtp.gmail.com", 587)
#connection must be done with a cryptographic protocol, in this case TLS at port 587 
server.starttls()
#once connection is established, program logs in with prev. made gmail username and password
server.login("username", "password")

#tests whether the user selected one of messages correctly
mess_test = True
while mess_test == True:
    if message == '1' or message == '2' or message == '3':
        mess_test = False 
    else:
        print "That's not an optional message. Try again."
        message = raw_input('Message: ')

#selects the message the user picked        
if message == '1':
    message = 'Your prescription is ready. Call xxx-xxx-xxxx with any questions.'
else:
    pass
if message == '2':
    message = 'Your prescription was attempted to be filled to early. Call xxx-xxx-xxxx with any questions.'
else:
    pass
if message == '3':
    message ="Your prescription needs more refills. We've called for Doctor's approval. Call xxx-xxx-xxxx with any questions."
else:
    pass

#sends the selected message to each element of prov_list    
for p in prov_list:
server.sendmail('name', p, message)

Tags: thetocomnumbermessageyourifwith