[英]Send email with Office365 python library `python-o365`
Ok So ive been able to send mail and read mail but I am now trying to attach an attachment to the mail and it doesnt seem to append the document as expected. 好了,我能够发送邮件和阅读邮件,但是我现在尝试将附件附加到邮件上,并且似乎没有按预期那样附加文档。 I dont get any errors but I also dont get the mail if I attempt to add the attachment. 我没有收到任何错误,但如果尝试添加附件,也不会收到邮件。
The library im using is here 我正在使用的图书馆在这里
The returned value frome the function is True
but an email never arrives if i remove the m.attachments.append('/path/to/data.xls')
line the email arrives as expected (without an attachment of course). 该函数返回的值为True
但如果我删除m.attachments.append('/path/to/data.xls')
行,则电子邮件按预期到达(当然没有附件),则电子邮件永远不会到达。
Code 码
def sendAddresses(username, password):
try:
authenticiation = (username, password)
m = Message(auth=authenticiation)
m.attachments.append('/path/to/data.xls')
m.setRecipients("email@address.com")
m.setSubject("Test Subject")
m.setBody("Test Email")
m.sendMessage()
except Exception, e:
print e
return False
return True
Please debug this way 请这样调试
att = Attachment(path=path)
att.save(path)
m.attachments.append(att)
I might be able to help. 我也许能帮上忙。 It looks like you may be having a problem related to this . 看来您可能有与此相关的问题。 Seth had the basic idea right. 赛斯(Seth)的基本想法正确 Make an attachment, then append the attachment to the message. 制作附件,然后将附件附加到邮件中。
You say that the message is failing to send. 您说邮件无法发送。 Can you post the contents of o365.log that is created when you call the send function? 您可以发布调用send函数时创建的o365.log的内容吗? That would help. 那会有所帮助。 Also, try updating to the latest version (0.9.4 at time of writing) and see if that doesn't fix some of your problems. 另外,请尝试更新到最新版本(在撰写本文时为0.9.4),看看这是否不能解决您的某些问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.