1
import smtplib def prompt(prompt): return raw_input(prompt).strip() fromaddr = prompt("From: ") toaddrs = prompt("To: ").split() print "Enter message, end with ^D (Unix) or ^Z (Windows):" msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs))) while 1: try: line = raw_input() except EOFError: break if not line: break msg = msg + line print "Message length is " + repr(len(msg)) server = smtplib.SMTP('smtp.live.com:25') server.set_debuglevel(1) server.sendmail(fromaddr, toaddrs, msg) server.quit() 

I'm trying to send an Email using that example, but it doesnt work, I dont get any error it just doesn't send anything, I'm trying to send it to a hotmail email. Any help will be appreciated, Thanks.

4
  • Your indentation suggests that server = .. is in while loop. I guess that is not what you intended. Commented Nov 5, 2010 at 3:33
  • sorry about that, I fixed the Identation. Commented Nov 5, 2010 at 3:47
  • Does your server require authentication? Does it fail silently if it doesn't get it? Commented Nov 5, 2010 at 3:55
  • I dont have a server, the server I want to send the message to is hotmail which is smtp.live.com:25 Commented Nov 5, 2010 at 21:15

1 Answer 1

2

Your call to smtplib.SMTP() uses invalid arguments. According to the smtplib docs:

SMTP([host[, port[, local_hostname[, timeout]]]])

So, the SMTP constructor takes the optional arguments for hostname, port etc. But you've passed port and hostname as one argument (server = smtplib.SMTP('smtp.live.com:25')).

Provided you have everything else right, if you change that line to read server = smtplib.SMTP('smtp.live.com', 25).

If your server requires authentication (and I suspect it does), before you actually send the email you'll want to call server.login(user, password) to login so you can actually send the message.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.