我有一个python代码,可以使用SMTP向手机发送短信。当我运行它时,我没有收到任何错误,但它不发送短信。我的代码还没有完成,现在我只是把基础知识搞定了。任何帮助发送它将不胜感激。
#infile = open('companyname.txt', 'r')
import sys
import smtplib
li_name = ["3 RIVER WIRELESS",
"ACS WIRELESS",
"ADVANTAGE COMMUNICATIONS",
"AIRTOUCH PAGERS",
"ALPHNOW",
"ALLTEL",
"ALLTELL PCS",
"AMERITECH PAGING",
"AMERITECH MESSAGING",
"AMERITECH CLEARPATH",
"ARCH PAGERS",
"AT&T",
"AT&T FREE2GO",
"AT&T PCS",
"AT&T POCKETNET PCS",
"BELL MOBILITY",
"BELL SOUTH BLACKBERRY",
"BELL SOUTH MOBILITY",
"BOOST",
"CELLULAR ONE EAST COAST",
"CELLULAR ONE SOUTH WEST",
"CELLULAR ONE PCS",
"CELLULAR ONE",
"CELLULAR ONE WEST",
"CELLULAR SOUTH",
"CENTENNIAL WIRELESS",
"CINGULAR",
"CINGULAR WIRELESS",
"COMCAST",
"HOUSTON CELLULAR",
"ILLINOIS VALLY CELLULAR",
"NEXTELL",
"SPRINT",
"SPRINT PCS",
"T-MOBILE",
"TRACFONE",
"VERIZON PAGERS",
"VERIZON",
"VIRGIN MOBILE",
"VIRGIN MOBILE CANADA"]
li_num = ["@sms.3rivers.net",
"@paging.acswireless.com",
"@advantagepaging.com",
"@alphapage.airtouch.com",
"@alphanow.net",
"@message.alltel.com",
"@message.alltel.com",
"@paging.acswireless.com",
"@page.americanmessaging.net",
"@clearpath.acswireless.com",
"@archwireless.net",
"@txt.att.net",
"@mmode.com",
"@mobile.att.net",
"@dpcs.mobile.att.net",
"@txt.bellmobility.ca",
"@bellsouthtips.com",
"@blsdcs.net",
"@myboostmobile.com",
"@phone.cellone.net",
"@swmsg.com",
"@paging.cellone-sf.com",
"@mobile.celloneusa.com",
"@mycellone.com",
"@csouth1.com",
"@cwemail.com",
"@mycingular.com",
"@mycingular.textmsg.com",
"@comcastpcs.textmsg.com",
"@text.houstoncellular.net",
"@ivctext.com",
"@messaging.nextel.com",
"@sprintpaging.com",
"@messaging.sprintpcs.com",
"@tmomail.net",
"@txt.att.net",
"@myairmail.com",
"@vtext.com",
"@vmobl.com",
"@vmobile.ca"]
again = 'y'
while again == 'y':
company_domain = ''
usr_company = str.upper(raw_input("Enter company: "))
if usr_company in li_name:
idx = li_name.index(usr_company)
company_domain = li_num[idx]
usr_number = raw_input("Enter phone number: ")
text_adr = usr_number + company_domain
sender = raw_input('enter "from" E-Mail address: ')
#if smtplib.SMTPSenderRefused(SMTPResponseException):
#print ('your email has been rejected by the server')
reciever = text_adr
message = ('Testing')
smtpObj = smtplib.SMTP('smtp.comcast.net')
smtpObj.sendmail(sender,reciever , message)
print "Successfully sent email"
smtpObj.quit()
else:
text_adr = "Company Not Found"
print ("your phone's email is:")
print text_adr
again = raw_input('Do you want to ask again?')
while again != 'y' and again != 'n':
print ('sorry that is an invalid answer!')
again = raw_input('Do you want to ask again?')
print
#old code:
#addr_from = raw_input ('enter your email address')
#addr_to = text_adr
#SMTP = 'smtp.comcast.net'
#msg = ('From: %s\r\nTo: %s\r\n\r\n'
#% (addr_from, ', '.join(addr_to)))
#msg = msg + 'This is the message'
#SMTP.sendmail(addr_from, addr_to, msg)
答案 0 :(得分:1)
从基础开始,启用smtp对象的调试,看看你得到了什么。
smtpObj = smtplib.SMTP('smtp.comcast.net')
smtpObj.set_debuglevel(10)
smtpObj.sendmail(sender,reciever , message)
答案 1 :(得分:1)
更改
smtpObj.sendmail(sender,reciever , message)
到
smtpObj.sendmail(sender,[reciever] , message)
因为sendmail
的第二个参数应该是电子邮件地址列表。
PS:您可能还想将reciever
更改为receiver
......:)