代码拉取完成,页面将自动刷新
同步操作将从 蜗牛勇士/网络设备自动巡检 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from exchangelib import DELEGATE, Account, Credentials, Message, Mailbox, HTMLBody, FileAttachment
from exchangelib.protocol import BaseProtocol, NoVerifyHTTPAdapter
import urllib3
# 忽略requests证书警告
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# 此句用来消除ssl证书错误,exchange使用自签证书需加上
BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter
def Email(subject, body, attachmentspath=None):
creds = Credentials(
username='helpdesk', # 账号
password='**********' # 密码
)
account = Account(
primary_smtp_address='helpdesk@abcd.com.cn', # 发送方邮箱地址
credentials=creds,
autodiscover=True,
access_type=DELEGATE
)
m = Message(
account=account,
subject=subject,
body=HTMLBody(body),
to_recipients=[Mailbox(email_address="zhangsan@abcd.com.cn"), Mailbox(email_address="lisi@abcd.com.cn")]
)
# 添加附件
attachments = []
with open(r"{}/巡检报告.pdf".format(attachmentspath), 'rb') as f:
content = f.read()
attachments.append(('巡检报告.pdf', content))
# 附加文件
for attachment_name, attachment_content in attachments or []:
file = FileAttachment(name=attachment_name, content=attachment_content)
m.attach(file)
m.send_and_save()
if __name__ == '__main__':
body = '网络设备自动巡检报告,脚本发送请勿回复。'
# "接收方的邮箱", "邮件标题", "邮件内容", "报告路径"
Email("网络设备巡检", body=body, attachmentspath=r'F:\PythonProgram\交换机巡检\LOG\2022-06-25_09-38-04')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。