我用 Python 编写了一个非常基本的脚本,可以让我更快/更轻松地发送电子邮件。我真的不打算每天使用它,它更像是我自己的概念证明。
我无法让主题行出现。我可以发送电子邮件,但是当我尝试使用我在此问题底部描述的方法包含主题行时,它只是不发送电子邮件(我知道该主题当前已被注释掉!)。这是我目前的代码:
import smtplib
candidate_name = raw_input("Candidate Name: ")
candidate_email = raw_input("Candidate Email: ")
# Specifying the from and to addresses
fromaddr = 'XXXX'
toaddrs = '%s' % candidate_email
#subject = 'Phone call'
# Writing the message (this message will appear in the email)
msg = '''
Hi %s
Thanks for taking my call just now. As discussed if you could send me a copy of your CV that would be great and I'll be back in touch shortly.
Cheers
XXXX''' %candidate_name
username = 'XXXX'
password = 'XXXX'
# Sending the mail
server = smtplib.SMTP('XXXX')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
print "Email sent to %s at %s" % (candidate_name, candidate_email)
server.quit()
我尝试将主题添加到发送邮件行,如下所示:
server.sendmail(fromaddr, toaddrs, subject, msg)
但它什么也没做。
我希望这不是一个非常愚蠢的问题。我才刚开始自学 Python。