Невозможно установить получателей - O365 - PullRequest
0 голосов
/ 12 марта 2019

Я пытаюсь отправить электронное письмо, используя 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='foobar@outlook.com', name='lucas') # dont work
msg._Message__to._recipients = [Recipient(address='foobar@outlook.com', name='lucas')] # works but very bad way i supossed
msg.setRecipients(Recipient(address='foobar@outlook.com', name='lucas')) # some old tutorials used this, but dont work either

msg.send()

Это, должно быть, очень глупый вопрос, но я прочитал классы из документа и не смог найти установщика для получателя.

Спасибо!

1 Ответ

0 голосов
/ 12 марта 2019

Нашел его в 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('foobar@outlook.com')

msg.send()
...