There appears to be some very knowledgeable people hanging around this forum so I post this question here even if it only indirectly is python related.
#SEMAIL returns ERROR
Is there any way of narrowing down what's wrong?
I've basically used the email sending example in pythonwin.
The APN and SMTP information is correct. I've verified that with my cellphone. I'm a little bit unsure about the AT#USERID and AT#PASSW. I've tried both nothing and guest/guest (online.telia.s e) with the same result.
#SEMAIL returns ERROR
Is there any way of narrowing down what's wrong?
I've basically used the email sending example in pythonwin.
The APN and SMTP information is correct. I've verified that with my cellphone. I'm a little bit unsure about the AT#USERID and AT#PASSW. I've tried both nothing and guest/guest (online.telia.s e) with the same result.
Code:
#Use serial import SER #Use build in module import MOD #Use AT command interface import MDM #Use GPS import GPS #Use sys? import sys # ########################################################### # # this values must be configured with valid ones.. # the one here are only for demo. # EMAIL_ADDRESS = "xxx@xxx.xx" # Yes, there's normally something else here... :) # this is the email address of the destinee of the mail (To:) # MY_EMAIL_ADDR = "xxx@xxx.xx" # Yes, there's normally something else here... :) # this is the email address of the source of the mail (From:) # usually (unless SMTP server permits relay) this must match # with MAIL_USER and MAIL_PASSW. # APN = "online.telia.se" # this is the access point for GPRS - ask your network operator # GPRS_USERID = "guest" # this is the User ID for GPRS - ask your network operator # GPRS_PASSW = "guest" # this is the Password for GPRS - ask your network operator # SMTP_SERVER = "mail.messagingengine.com" # this is the SMTP server that forwards the mail # MAIL_USER = "xxx@xxx.xx" # Yes, there's normally something else here... :) # this is the Username for the SMTP server # MAIL_PASSW = "*********" # Yes, there's normally something else here... :) # this is the Password for the SMTP server # # ########################################################### # def sendemail(): global sendingemail res = MDM.send('AT#SEMAIL="', 0) res = MDM.send(EMAIL_ADDRESS, 0) res = MDM.send('",', 0) res = MDM.send('"test email"', 0) res = MDM.send(',0', 0) res = MDM.sendbyte(0x0d, 0) res = MDM.receive(100) print 'AT#SEMAIL="%s","test email",0 returned %s' % (EMAIL_ADDRESS, res) res = MDM.send('email sent from python script', 0) print 'email content returned %s' % res res = MDM.send('\x1a', 0) print 'x1a returned %s' % res sendingemail = 1 print 'sending email ...' SER.set_speed('115200','8N1') class SerWriter: def write(self,s): SER.send(s+'\r') sys.stdout = sys.stderr = SerWriter() print 'Running...' MDMdata = '' sendingemail = 0 print 'initialize' res = MDM.send('AT+CGDCONT=1,"IP","',0) res = MDM.send(APN,0) res = MDM.send('","0.0.0.0",0,0\r', 0) res = MDM.receive(10) print 'AT+CGDCONT=1,"IP","%s","0.0.0.0",0,0 returned %s' % (APN, res) res = MDM.send('AT#USERID="',0) res = MDM.send(GPRS_USERID,0) res = MDM.send('"\r', 0) res = MDM.receive(10) print 'AT#USERID="%s" returned %s' % (GPRS_USERID, res) res = MDM.send('AT#PASSW="',0) res = MDM.send(GPRS_PASSW,0) res = MDM.send('"\r', 0) res = MDM.receive(10) print 'AT#PASSW="%s" returned %s' % (GPRS_PASSW, res) res = MDM.send('AT#ESMTP="',0) res = MDM.send(SMTP_SERVER,0) res = MDM.send('"\r', 0) res = MDM.receive(10) print 'AT#ESMTP="%s" returned %s' % (SMTP_SERVER, res) res = MDM.send('AT#GPRS=0\r', 0) res = MDM.receive(10) print 'AT#GPRS=0 returned %s' % res res = MDM.send('AT#EUSER="',0) res = MDM.send(MAIL_USER,0) res = MDM.send('"\r', 0) res = MDM.receive(10) print 'AT#EUSER="%s" returned %s' % (MAIL_USER, res) res = MDM.send('AT#EPASSW="',0) res = MDM.send(MAIL_PASSW,0) res = MDM.send('"\r', 0) res = MDM.receive(10) print 'AT#EPASSW="%s" returned %s' % (MAIL_PASSW, res) res = MDM.send('AT#EADDR="',0) res = MDM.send(MY_EMAIL_ADDR,0) res = MDM.send('"\r', 0) res = MDM.receive(10) print 'AT#EADDR="%s" returned %s' % (MY_EMAIL_ADDR, res) res = MDM.send('AT#ESAV\r', 0) res = MDM.receive(20) print 'AT#ESAV returned %s' % res timerA = MOD.secCounter() timerAstop = timerA + 10 timerArunning = 1 while 1: if timerArunning: timerA = MOD.secCounter() if timerA > timerAstop: res = MDM.send('AT#EMAILACT=1\r', 0) res = MDM.receive(100) print 'AT#EMAILACT=1 returned %s' % res if(res.find('OK') != -1): res = MDM.send('AT+CGDCONT?\r', 0) res = MDM.receive(20) print 'AT+CGDCONT? returned %s' % res res = MDM.send('AT+COPS?\r', 0) res = MDM.receive(20) print 'AT+COPS? returned %s' % res res = MDM.send('AT+CSQ\r', 0) res = MDM.receive(20) print 'AT+CSQ returned %s' % res res = MDM.send('AT+CGATT?\r', 0) res = MDM.receive(20) print 'AT+CGATT? returned %s' % res print 'send email' sendemail() timerArunning = 0 MOD.sleep(200) else: print 'email init failed' MOD.sleep(200) MDMdata = MDM.read() if MDMdata != '': if sendingemail: print 'MDM read data %s' % MDMdata sendingemail = 0 else: print 'unexpected data' print 'MDM read data %s' % MDMdata
Comment