0
有人可以帮我从我的交换账户发送电子邮件并添加附件。 SMTP不起作用,我收到了即时超时问题。 0365不会将副本保存到我发送的文件夹中。其他唯一的一个我所知道的是exchangelib
如何发送带有Python和Microsoft Exchange附件的电子邮件?
from exchangelib import Account, Credentials, Message, Mailbox, FileAttachment
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import formatdate
from email import encoders
email = 'XXXXXXXX'
password = 'XXXXXXXX'
a = Account(email, credentials=Credentials(email, password), autodiscover=True)
dir_path = ('C:/Users/Istcrmt/Documents/Python/PythonforAnaconda3.5/')
excel_name = 'test.xlsx'
#attach an excel file:
for i in email_list.itertuples():
# if you want a copy in the 'Sent' folder
m = Message(
account=a
,folder=a.sent
,subject=(i.AGENCY_NAME + ' I made an email script.')
,body='All bodies are beautiful'
,to_recipients=[Mailbox(email_address=i.NEW_MAIL)])
#attach files
m.attachments.append(part)
# m.attach(cover_letter)
m.send_and_save()
SMTP应该工作;你确定你已经连接到SMTP吗? – pstatix
哦不,我不能做一个连接,这是我的问题 – Tinkinc
即使超时参数和或ssl我得到超时 – Tinkinc