mail_shooter.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:DualisWatcher 作者: LucaVazz 项目源码 文件源码
def send(self, target: str, subject: str, html_content_with_cids: str, inline_png_cids_filenames: {str : str}):
        msg = EmailMessage()
        msg['Subject'] = subject
        msg['From'] = self.sender
        msg['To'] = target

        msg.set_content('')

        msg.add_alternative(
            html_content_with_cids, subtype='html'
        )

        for png_cid in inline_png_cids_filenames:
            full_path_to_png = os.path.abspath(os.path.join(
                os.path.dirname(__file__), inline_png_cids_filenames[png_cid]
            ))
            with open(full_path_to_png, 'rb') as png_file:
                file_contents = png_file.read()
                msg.get_payload()[1].add_related(file_contents, 'image', 'png', cid=png_cid)

        with smtplib.SMTP(self.smtp_server_host, self.smtp_server_port) as smtp_connection:
            smtp_connection.starttls()
            smtp_connection.login(self.username, self.password)
            smtp_connection.send_message(msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号