简体   繁体   English

使用Office365 python库`python-o365`发送电子邮件

[英]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.

相关问题 Python:如何将电子邮件文本正文传递给Office365电子邮件 - Python: How to pass email text body to Office365 Email 无法发送电子邮件 nodemailer / office365 - Unable to send email nodemailer / office365 python smtplib 未发送 email 与 office365 地址 - python smtplib not sending email with office365 address 如何使用 tls/ssl 将 SMTP email 发送到 office365 和 python - How to send SMTP email for office365 with python using tls/ssl O365用Python发送电子邮件附件 - O365 Send email attachment in Python 如何使用基于 web 应用程序的身份验证在 Python Django 中使用 Microsoft graph api (python-o365) 发送和阅读邮件? - How to send and read mail using Microsoft graph api (python-o365) in Python Django using web app based authentication? 使用 Python 访问 Office365 Sharepoint REST 端点(Python 的 Office365 Sharepoint REST 客户端) - Accessing Office365 Sharepoint REST EndPoints using Python (Office365 Sharepoint REST client for Python) 如何使用 office365 在 Django 中发送 Email - How to send Email in Django using office365 使用 python-o365 将 Microsoft Graph 导出到 pdf 会提供无效文件 - Microsoft Graph export to pdf using python-o365 gives invalid file Python Office365 API-TimeZone保持本地时间 - Python Office365 API - TimeZone stays at Local Time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM