首页 > Python:通过邮箱发送贺卡或明信片

Python:通过邮箱发送贺卡或明信片

请问,使用python可以发送贺卡或明信片吗?
还是只能发送普通邮件?


自带的smtplib本身就支持发送HTML邮件

def send_mail(self, recipients, subject, body):
        msg = MIMEMultipart('alternative')
        msg.set_charset("utf-8")
        msg['Subject'] = subject
        msg['From'] = self.__email_from
        msg['To'] = ";".join(recipients)

        body = MIMEText(body, 'html', "utf-8")
        msg.attach(body)

        try:
            client = smtplib.SMTP(self.__smtp_server_host)
            client.login(self.__smtp_user_name, self.__smtp_user_password)
            client.sendmail(self.__email_from, recipients, msg.as_string())
            return True
        except Exception, e:
            traceback.print_exc()
            logging.error(e)
            return False

关键是你能不能把你的邮件构造成你想要的


邮件内容可以包含HTML的格式。所以是可以实现的。

【热门文章】
【热门文章】