| Reply | « Previous Thread | Next Thread » |
|
Hello, I just started with PyS60 yesterday and with some code snippets and some tutorials I got a script running to send an email to a server using smtplib.SMTP(SERVER) and login(user,pass). Everything is working fine.
But now I want to make a SIS file, that worked fine too, but after the SIS file is installed to the phone, the app can't use the login function anymore. The script is still doing what it should do. Code:
try:
SUBJECT = "Test"
TO = ["my@email.de"]
FROM = "my@email.de"
TEXT = "This test was a success."
SERVER = "mail.server.de"
message = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# first the error occured here, but then i set the py2sis mode to pys60
server = smtplib.SMTP(SERVER)
# now the error occurs here
server.login("user", "pass")
server.sendmail(FROM, TO, message)
server.quit()
appuifw.note(u"Success.", "info")
except:
appuifw.note(u"Error.", "error")
|
| Karandaras |
| View Public Profile |
| Find all posts by Karandaras |
|
Join Date: Nov 2007
Posts: 317
Location: Sertaozinho/Brazil
marcelobarrosalmeida
Online
Forum Nokia Champion
|
|
Hi Karandaras
Do you know exactly in which line the program is failing ? How about to use something to show the error message ? This way it will be easier to help you. Code:
...
...
except Exception, e:
note(unicode(e),"error")
raise
Marcelo Barros Nokia E71, N800, N95 and XM 5800 http://www.croozeus.com http://wordmobi.wordpress.com http://jedizone.wordpress.com |
|
I added the line of code you suggested and now it shows me the following:
(501, '5.0.0 invalid domain name') but executed as a script it sends the mail without errors. I also added some print commands between the lines to the script to identify the line in which the error occurs, it occurs here: server.login("user", "pass") but I can't explain why, because the script version is running fine Again, thanks in advance. |
| Karandaras |
| View Public Profile |
| Find all posts by Karandaras |
|
Join Date: Nov 2007
Posts: 317
Location: Sertaozinho/Brazil
marcelobarrosalmeida
Online
Forum Nokia Champion
|
|
It is really strange to have only the script running ...
So, 501 in SMTP is "Syntax error in parameters or arguments" But invalid domain name is related to DNS ... DNS error ?Are you seeing the connection icons on your phone ? How about to pre-select your access point before accessing the smtp server ? Just for ensure the connection was done properly. Code here: http://croozeus.com/blogs/?p=836 Marcelo Barros Nokia E71, N800, N95 and XM 5800 http://www.croozeus.com http://wordmobi.wordpress.com http://jedizone.wordpress.com |
|
Thanks, setting the access point helped.
Now everything works like it should. |
| Karandaras |
| View Public Profile |
| Find all posts by Karandaras |
|
I found the error, it's the selected access point. Found it after the error occured on my phone too.
The error occured again but without making changes. This time it's even more weird. Everything is working fine on my Nokia 5800 XM but on my friend's Nokia 5800 XM only the script is working like intended. And what's even more wierd is that a few days ago it worked fine and now, after she had to make a hard reset it's not working anymore although I reinstalled everything related to python. The SIS file starts but can't send an email. The error occurs here: Code:
server = smtplib.SMTP(SERVER)
server.login(user,pass) # This one throws the error
server.sendmail(FROM, TO, message.encode("utf-8"))
server.quit()
Here is the complete code: Code:
# -*- coding: utf-8 -*-
import appuifw, contacts, e32, os, smtplib, sys, btsocket
class ContactList:
def __init__(self, sortable = None):
self.__db = contacts.open()
self.__contact = []
self.__number = {}
self.__load_contact(sortable)
def __load_contact(self, sortable = None):
for id in self.__db:
try:
name = self.__db[id].title
mobile = self.__db[id].find('mobile_number')
phone = self.__db[id].find('phone_number')
number_tmp = []
if mobile:
number_tmp.extend([field.value for field in mobile])
if phone:
number_tmp.extend([field.value for field in phone])
self.__number[name] = number_tmp
self.__contact.append(name)
if sortable:
self.__contact.sort(sortable)
except:
None
def select_multi(self):
index = appuifw.multi_selection_list(self.__contact, 'checkbox', 1)
if not index:
return None
multi_number = []
for i in index:
number_list = self.__number[self.__contact[i]]
if not number_list:
continue
if len(number_list) > 1:
ind = appuifw.popup_menu(number_list, u"Nummer wählen")
if ind == None:
continue
else:
ind = 0
multi_number.append(number_list[ind])
if multi_number:
return multi_number
else:
return None
#The Class ends the Program starts
def write_settings():
CONFIG_DIR="e:/"
CONFIG_FILE=os.path.join(CONFIG_DIR,'smstrade.txt')
if not os.path.isdir(CONFIG_DIR):
os.makedirs(CONFIG_DIR)
CONFIG_FILE=os.path.join(CONFIG_DIR,'smstrade.txt')
config={}
if key:
config['key']= key
if yournum:
config['yournum']= yournum
if type:
config['type']= type
if email:
config['email']= email
if em_user:
config['em_user']= em_user
if em_pass:
config['em_pass']= em_pass
if em_server:
config['em_server']= em_server
if apid:
config['apid']= apid
f=open(CONFIG_FILE,'wt')
f.write(repr(config))
f.close()
def read_settings():
CONFIG_FILE=os.path.join("e:/",'smstrade.txt')
try:
f=open(CONFIG_FILE,'rt')
try:
content = f.read()
config=eval(content)
f.close()
global key
key=config.get('key',None)
global yournum
yournum=config.get('yournum',None)
global type
type=config.get('type',None)
global email
email=config.get('email',None)
global em_user
em_user=config.get('em_user',None)
global em_pass
em_pass=config.get('em_pass',None)
global em_server
em_server=config.get('em_server',None)
global apid
apid=config.get('apid',None)
except:
print 'can not read file'
except:
print 'can not open file'
def set_accesspoint():
global apid
apid = btsocket.select_access_point()
apo = btsocket.access_point(apid)
btsocket.set_default_access_point(apo)
if apid:
write_settings()
else:
apid = None
def item1():
global key
global nums
global type
global yournum
global email
global em_user
global em_pass
global em_server
global apid
if key:
if nums:
if type:
if yournum:
if email:
if em_user:
if em_pass:
if em_server:
try:
try:
if not apid == None :
apo = btsocket.access_point(apid)
btsocket.set_default_access_point(apo)
else:
set_accesspoint()
except:
set_accesspoint()
SUBJECT = appuifw.app.body.get()
TO = ["email2sms@smstrade.de"]
FROM = email
TEXT = "#" + key + "#" + nums + "#" + type + "#" + yournum
message = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" % (FROM, ", ".join(TO), SUBJECT, TEXT)
SERVER = em_server
server = smtplib.SMTP(SERVER)
server.login(em_user, em_pass)
server.sendmail(FROM, TO, message.encode("utf-8"))
server.quit()
appuifw.note(u"E-Mail2SMS Versand erfolgt.", "info")
global t
t.clear()
nums = None
except Exception, e:
appuifw.note(unicode(e), "error")
else:
appuifw.note(unicode("E-Mail Server nicht gesetzt"), "error")
else:
appuifw.note(unicode("E-Mail Passwort nicht gesetzt"), "error")
else:
appuifw.note(unicode("E-Mail Benutzer nicht gesetzt"), "error")
else:
appuifw.note(unicode("E-Mail Abesender nicht gesetzt"), "error")
else:
appuifw.note(unicode("Absender Nummer nicht gesetzt"), "error")
else:
appuifw.note(unicode("SMS Typ nicht gesetzt"), "error")
else:
appuifw.note(unicode("Empfänger nicht gesetzt"), "error")
else:
appuifw.note(unicode("Gateway Key nicht gesetzt"), "error")
def item2():
global nums
nums = ""
test = ContactList(lambda x, y:cmp(x, y))
if test:
mnum = test.select_multi()
try:
nums = ",".join(mnum)
except:
nums = None
else:
nums = None
def item3():
global yournum
yournum = appuifw.query(u"Absender:", "text")
if yournum:
write_settings()
else:
yournum = None
def item4():
global key
key = appuifw.query(u"Gateway-Key:", "code")
if key:
write_settings()
else:
key = None
def item5():
global type
types = [u"basic",u"economy",u"gold"]
type = types[appuifw.popup_menu(types)]
if type:
write_settings()
else:
type = None
def item6():
global email
email = appuifw.query(u"E-Mail:", "text")
if email:
write_settings()
else:
email = None
def item7():
global em_user
em_user = appuifw.query(u"E-Mail Benutzer:", "text")
if em_user:
write_settings()
else:
em_user = None
def item8():
global em_pass
em_pass = appuifw.query(u"E-Mail Passwort:", "code")
if em_pass:
write_settings()
else:
em_pass = None
def item9():
global em_server
em_server = appuifw.query(u"E-Mail Server:", "text")
if em_server:
write_settings()
else:
em_server = None
def numchars():
c = appuifw.app.body.len()
appuifw.app.title = u'SMSTrade Email2SMS (%d)' % c
appuifw.app.menu = [(u"Zählen", numchars),
(u"Abschicken", item1),
(u"Empfänger setzen", item2),
(u"SMS Einstellungen",
((u"Absender setzen", item3),
(u"Gateway-Key setzen", item4),
(u"SMS Typ setzen", item5))),
(u"EMail Einstellungen",
((u"E-Mail Adresse setzen", item6),
(u"E-Mail Benutzer setzen", item7),
(u"E-Mail Passwort setzen", item8),
(u"E-Mail Server setzen", item9))),
(u"AccessPoint setzen", set_accesspoint)]
app_lock = e32.Ao_lock()
appuifw.app.title = u'SMSTrade Email2SMS (0)'
appuifw.app.screen='normal'
key = None
nums = None
type = None
yournum = None
email = None
em_user = None
em_pass = None
em_server = None
apid = None
read_settings()
t = appuifw.Text()
appuifw.app.body = t
t.color = 0x000000
t.font = (u"Nokia Hindi S60", 25, None)
t.highlight_color = 0xC3C3C3
app_lock.wait()
Last edited by Karandaras : 2009-10-10 at 11:50.
Reason: Problem found.
|
| Karandaras |
| View Public Profile |
| Find all posts by Karandaras |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |