我正在尝试使用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。
谢谢!
发现它在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()