views:

316

answers:

3

I have a python code to send a text message to your cellphone using SMTP. when I run it I don't get any errors, but it doesn't send the text message. My code isn't finished, right now I am just getting the basics down. Any help on making it send would be appreciated.

#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)
+1  A: 

Start with the basics, enable debugging for the smtp object and see what you get.

smtpObj = smtplib.SMTP('smtp.comcast.net')         
smtpObj.set_debuglevel(10)
smtpObj.sendmail(sender,reciever , message)

You can read about the set_debuglevel call here.

qor72
after I used both of you guys' code it says this, this is only some of it, because it wouldn't let me put it on the comment: send: 'ehlo [192.168.1.100]\r\n' reply: '250-omta09.westchester.pa.mail.comcast.net hello [76.107.170.219], pleased to meet you\r\n' send: 'data\r\n' reply: '354 enter mail, end with "." on a line by itself\r\n' reply: retcode (354); Msg: enter mail, end with "." on a line by itself data: (250, '2.0.0 3X7V1e00D4kMwMY3VX7V8L mail accepted for delivery')
justin
Well, that last part says it took your message (the 250...) and will attempt to deliver it. You sure you have the to/from/data sorted out properly?I know this can be done, I put together a python library for Nagios at a previous job to do similar; send email txts to on call support staff.
qor72
now how would I write that reply to a txt file?
justin
Using smtplib, never tried. The dox (http://docs.python.org/library/smtplib.html) say that if you don't get an exception that the mail must be assumed sent. That's the best your going to get without going deeper, or handling the handshakes yourself.
qor72
it says: reply: retcode (354); Msg: enter mail, end with "." on a line by itselfdata: (354, 'enter mail, end with "." on a line by itself') but I don't know how to do that
justin
You already did. What you are seeing is the SMTP transaction log. That's every command being sent from smtplib to the smtp server -- even stuff you don't have to do. If you are still using the sendmail function it'll send everything properly.
qor72
A: 

Change

smtpObj.sendmail(sender,reciever , message)

to

smtpObj.sendmail(sender,[reciever] , message)

since the second argument to sendmail should be a list of email addresses.

PS: You might want to change reciever to receiver too... :)

unutbu
A: 

i need smtp to power ams mail?

James Paul