我正在使用以下代码从 unix 发送电子邮件。
代码
#!/usr/bin/python
import os
def sendMail():
sendmail_location = "/usr/sbin/sendmail" # sendmail location
p = os.popen("%s -t" % sendmail_location, "w")
p.write("From: %s\n" % "myname@company.com")
p.write("To: %s\n" % "yourname@company.com")
p.write("Subject: My Subject \n")
p.write("\n") # blank line separating headers from body
p.write("body of the mail")
status = p.close()
if status != 0:
print "Mail Sent Successfully", status
sendMail()
我不确定如何在这封电子邮件中添加附件(附件位于不同的目录 /my/new/dir/)