-1

有人可以告诉我,下面的代码有什么问题吗?TIA :)))

import smtplib
if raw_input("if you want to send a message from a gmail account, type yes: ") == 'yes':
    try:      
        sender = raw_input("from:\n")
        senders_pwd = raw_input("password:\n")
        recipient = raw_input("to:\n")
        print 'ok, now compile your message:'
        subject = raw_input("subject:\n")
        body = raw_input("your message:\n")
        message = "subject: %s\n%s" %(subject,body)

        server = smtplib.SMTP("smtp.gmail.com",587)
        server.ehlo()
        server.starttls()
        server.ehlo()
        print "ok, I've sent your email"
    except:
        print 'failed to send'
4

1 回答 1

1

您需要调用 sendmail() 函数。在最后一个 server.ehlo() 之后添加类似以下三行的内容:

server.login(sender, senders_pwd)
server.sendmail(sender, recipient, message)
server.close()
于 2013-11-08T13:27:08.830 回答