我已经能够使用'python-o365‘库成功地连接和阅读电子邮件:
Connection.oauth2('Client_ID','Client_Secret',store_token=True)
inbox = FluentInbox()
for message in inbox.fetch_next(2):
print(message.getSubject())
但是,当我尝试使用更基本的示例发送电子邮件时,我收到了来自服务器的401
响应。
Connection.oauth2('Client_ID','Client_Secret',store_token=True)
att = Attachment(path=FilePath)
m = Message()
m.setRecipients(EmailTo)
m.setSubject('DBM Errors Identified - ' + FileName)
m.setBody(MessageBody)
m.attachments.append(att)
m.sendMessage()
我还尝试了设置connection对象并将其作为参数传递:
auth = Connection.oauth2('Client_ID','Client_Secret',store_token=True)
m = Message(*auth=auth*)
但是,这会导致以下错误消息:
TypeError: 'Connection' object is not callable
谢谢你的帮助!
发布于 2018-08-22 04:06:10
通过切换到上面使用的'python-o365‘库的fork,我能够绕过这个问题。我觉得我可能在这个库中遗漏了一些明显的东西,但这解决了问题
下面是我的身份验证流的简化版本,如果有人感兴趣的话:
scopes = ['https://graph.microsoft.com/Mail.Read'']
account = Account(('Client_Id', 'Client_Secret'], auth_method='oauth',scopes=scopes)
account.connection.get_authroization_url() #generate the url for user to authenticate
result_url = input('Paste the result URL once you have authenticated...')
account.connection.get_session() #generate a session
m = account.new_message()
m.to.add('EmailTo')
m.body = 'MessageText'
m.send()
https://stackoverflow.com/questions/51934845
复制相似问题