2
나는 매일 아침 발송하는 일부 전자 메일을 자동화하려고합니다. 여러 첨부 파일을 포함 할 때 몇 가지 문제가 있으며 어디서 잘못 될지 파악할 수 없습니다.Python 3.6 TypeError : 사무실에 보낼 때 문자열 인덱스가 정수 여야합니다. 365 전자 메일
다음from O365 import Message, Attachment
import getpass
email_list = {
'email1': {
'recipients': '[email protected]',
'subject': 'test subject',
'body': 'test body',
'files': ["file1.xlsx", "file2.xlsx"]
}
'email2': {
'recipients': '[email protected]',
'subject': 'test subject',
'body': 'test body',
'files': ["file3.xlsx", "file4.xlsx"]
}
}
username = input('Enter your email: ')
password = getpass.getpass('Enter your password: ')
o365_auth = (username, password)
def daily_email(recipients, subject, body, files):
m = Message(auth=o365_auth)
m.setRecipients(recipients)
m.setSubject(subject)
m.setBody(body)
for file in files:
att = Attachment(file)
m.attachments.append(att)
m.sendMessage()
for email, email_contents in email_list.items():
daily_email(email_contents['recipients'], email_contents['subject'], email_contents['body'], email_contents['files'])
오류가 나는받을 수있다 :
Traceback (most recent call last):
File ".\emails2.py", line 46, in <module>
email_contents['files'])
File ".\emails2.py", line 34, in daily_emails
att = Attachment(file)
File "C:\Users\adiosz\AppData\Local\Programs\Python\Python36-32\lib\site-packages\O365\attachment.py", line 50,
in __init__
self.isPDF = '.pdf' in self.json['Name']
TypeError: string indices must be integers
감사합니다!
'print()'를 사용하여 값을 변수에 표시하여 보유하고있는 것을 확인하십시오. – furas