| Author |
Python Email Program (need help debugging) |
psychboo
Member

Posts: 1
Location: Canada
Joined: 11.06.10 Rank: Mad User |
|
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?
#! /usr/bin/env python
import smtplib
import getpass
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
Edited by psychboo on 18-06-10 23:40 |
|
| Author |
RE: Python Email Program (need help debugging) |
wolfmankurd
Member

Posts: 1519
Location: UK
Joined: 30.05.05 Rank: God |
|
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.
BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.

|
|
| Author |
RE: Python Email Program (need help debugging) |
ynori7
Future Emperor of Earth

Posts: 1481
Location: #valhalla
Joined: 08.10.07 Rank: Diabolical |
|
|
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.
|
|
| Author |
RE: Python Email Program (need help debugging) |
wolfmankurd
Member

Posts: 1519
Location: UK
Joined: 30.05.05 Rank: God |
|
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.
BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.

Edited by wolfmankurd on 19-06-10 12:31 |
|
| Author |
RE: Python Email Program (need help debugging) |
only_samurai
[IRC Rockstar]
Posts: 984
Location: idling in some random irc channel
Joined: 18.08.06 Rank: .|unranked|. |
|
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 descblockedription explaining where the problem is?
The problem with a fool-proof system, is eliminating the fool.
"His name is Cereal Killer...Like Fruitloops." If you cut me, I bleed binary.
http://blog.psych0tik.net/ |
|
| Author |
RE: Python Email Program (need help debugging) |
4rm4g3dd0n
Member

Posts: 904
Location: Louisville,Ky
Joined: 09.10.07 Rank: God |
|
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
|
|