无法设置收件人 - O365

问题描述 投票:0回答:1

我正在尝试使用O365发送电子邮件

但是,我找不到一种方法来设置收件人而不访问私有属性。

from O365 import *

my_protocol = MSGraphProtocol(api_version='beta')
account = Account(
    credentials=('id', 'id'),
    protocol=my_protocol
)
if not account.is_authenticated:  # will check if there is a token and has not expired
    # ask for a login
    account.authenticate(scopes=['mailbox', 'message_send'])

msg = Message(parent=account)
msg.body = 'Hi, foobar.'
msg.subject = 'Bar Foo'

msg.to = Recipient(address='[email protected]', name='lucas') # dont work
msg._Message__to._recipients = [Recipient(address='[email protected]', name='lucas')] # works but very bad way i supossed
msg.setRecipients(Recipient(address='[email protected]', name='lucas')) # some old tutorials used this, but dont work either

msg.send()

这一定是一个非常愚蠢的问题,但是我从文档中读取了这些类,但找不到收件人的setter。

谢谢!

python office365api
1个回答
0
投票

发现它在github

msg.to.add('email')

此功能添加收件人。如果你传递一个字符串列表,或许多。

最终代码:

from O365 import *

my_protocol = MSGraphProtocol(api_version='beta')
account = Account(
    credentials=('id', 'id'),
    protocol=my_protocol
)
if not account.is_authenticated:  # will check if there is a token and has not expired
    # ask for a login
    account.authenticate(scopes=['mailbox', 'message_send'])

msg = Message(parent=account)
msg.body = 'Hi, foobar.'
msg.subject = 'Bar Foo'

msg.to.add('[email protected]')

msg.send()
© www.soinside.com 2019 - 2024. All rights reserved.