MOA
Security & Administration
Tuesday, June 22, 2010
A simple Python 3 Email with google's smtp.
The code:
import smtplib
def promt(promt):
return input(promt).strip()
# inputs the addresses
fromaddr=promt("From: ")
toaddrs=promt("To: ").strip()
print ("Enter message end with ^D (Unix) or ^Z (Winfail): ")
msg=("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, ", ".join(toaddrs)))
while True: # loop
try:
line=input()
except EOFError:
break
if not line:
break
msg=msg+line
print ("Message Lenght is ", len(msg)) # prints the lenght of the message
server=smtplib.SMTP("smt.gmail.com",587) # server used to send smtp mail
server.starttls() # tls
server.set_debuglevel(1) # remove this if you dont want to use debuglevel
server.login('emailaddr@gmail.com','Password') # enter your smtp address and password
server.sendmail(fromaddr, toaddrs, msg) # sends the email
server.quit()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment