![](/img/trans.png)
[英]Sending E-Mail with attachment automatically to person with delay in Python
[英]Sending an Attachment with e-mail using Python
我正在尝试使用以下代码发送带有电子邮件的附件。 但它给出了一个错误。 没有附件,它可以完美地工作。 这段代码有什么问题?
"mail5.py", line 14
smtpObj = smtplib.SMTP('domain', 25)
^
SyntaxError: invalid syntax
#!/usr/bin/python
import smtplib
sender = 'a@a.com'
receivers = ['b@b.com']
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
msg = MIMEMultipart()
msg.attach(MIMEText(file("text.txt").read())
smtpObj = smtplib.SMTP('domain', 25)
smtpObj.sendmail(sender, receivers, msg.as_string())
print "Successfully sent email"
看起来你错过了前一行的右括号,试试这个:
msg.attach(MIMEText(file("text.txt").read()))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.