I've modified a program I found in the code bank that uses python and the smtplib module in order to send through Gmail servers.
I'm new to python and trying to figure out why the following code is generating errors when run.
Any advice?
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
x = smtpserver.ehlo()
print "Connected to "+x[1].split()[0]+" at "+x[1].split()[4]+'\n'
x = smtpserver.starttls()
print x[1]
logged_in = False
print 'Login Required \n'
while not logged_in:
gmail_user = raw_input("User: ")
gmail_pwd = getpass.getpass()
try:
smtpserver.login(gmail_user,gmail_pwd)
logged_in = True
except smtplib.SMTPAuthenticationError:
print 'Incorrect User/Pass combination\n'
print 'Accepted'
to = raw_input("Send to: ")
subject = raw_input("Subject: ")
header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + subject + '\n'
print '\n'+header+'\n'+'Type your email below, *q terminates\n'
msg=''
while msg[-3:]!='*q\n':
msg+=raw_input('>')+'\n'
x=''
while x!='y' and x!='n':
x=raw_input('Send? (y/n): ')
if x=='y':
smtpserver.sendmail(gmail_user, to, msg)
smtpserver.close()
If the code seems convoluted PM me and i'll send you a .txt
I haven't had a look at it cause like you hinted it looks like eye rape without formatting. Tried the [code] tags? Idk if they protect the formatting? Also post the error outputed it maybe the case that we don't need to run it know the problem.
Posts: 1486 Location: #valhalla Joined: 08.10.07 Rank: God
Posted on 19-06-10 04:28
wolfmankurd wrote:
Idk if they protect the formatting?
They do, keeps the tabs and all and it eliminates smileys.
Most people (myself included) won't read code that's more than a few lines long if it doesn't have tabbing. Especially in python since you can't tell what stuff is contained in what loops without tabs.
It'd be pretty sweet if we had code bin style formatting from the [code] tags. Like keyword colouring. Op why not just post a link to codebin.
Anyway I can't quiet work out your formatting I tried it in http://codepad.org/ (which is an awesome site someone posted in the IRC I think it was NotMyFault). If you put it on there and link us then we'd have the pastebin style formatting and highlighting and be able to see the errors on the fly.
Edited by on 19-06-10 12:31
Author
RE: Python Email Program (need help debugging)
Member
Posts: Location: Joined: 01.01.70 Rank: Guest
Posted on 19-06-10 16:32
Additionally, could you post a stack trace of the error the program is having? If it's not a programmatic error and is a logical error (e.g. the program runs but doesn't do what you think it's supposed to), could you post a brief description explaining where the problem is?
there are language differences between python 2 and python 3
myself i prefer 2 but that's because most of the code I've written was in 2
and I don't like modifying all the time
try " instead of ' for boolean text if using python 3 I've had problems with that plus annoying small things like
print "printed"
print ("printed"
from md5 import new
from hashlib
x = hashlib.md5 ("string"
new = hashlib.update (x)
and so on
All I Know Is That I Don't Know Nothing .... Operation Ivy