使用 smtp 从 Python 发送邮件,移动 phone 中没有内容
Send mail from Python using smtp, no content in mobile phone
我正在使用Python smtp 模块发送邮件,发送成功并且在outlook 中看起来不错。当我在移动 phone 中签入时,它没有内容,只有 attachment.Actually 内容中有三个表格。有谁知道如何解决这个问题?下面是我的代码。
def send_mail(subject, sender, recipient, cc, toaddrs, body, filename):
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = ", ".join(recipient)
msg['Cc'] = ", ".join(cc)
message = MIMEText(body, 'html') # html.read(), 'html')
msg.attach(message)
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(open(filename, 'rb').read())
encoders.encode_base64(attachment)
attachment.add_header(
'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
msg.attach(attachment)
smtp = smtplib.SMTP('localhost')
smtp.sendmail(sender, toaddrs, msg.as_string())
logger.info('Email have sent successfully!')
smtp.quit()
任何帮助将不胜感激。
谢谢
通过附件解决这个问题,然后附上消息。
def send_mail(subject, sender, recipient, cc, toaddrs, body, filename):
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = ", ".join(recipient)
msg['Cc'] = ", ".join(cc)
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(open(filename, 'rb').read())
encoders.encode_base64(attachment)
attachment.add_header(
'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
msg.attach(attachment)
message = MIMEText(body, 'html') # html.read(), 'html')
msg.attach(message)
smtp = smtplib.SMTP('localhost')
smtp.sendmail(sender, toaddrs, msg.as_string())
logger.info('Email have sent successfully!')
smtp.quit()
我正在使用Python smtp 模块发送邮件,发送成功并且在outlook 中看起来不错。当我在移动 phone 中签入时,它没有内容,只有 attachment.Actually 内容中有三个表格。有谁知道如何解决这个问题?下面是我的代码。
def send_mail(subject, sender, recipient, cc, toaddrs, body, filename):
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = ", ".join(recipient)
msg['Cc'] = ", ".join(cc)
message = MIMEText(body, 'html') # html.read(), 'html')
msg.attach(message)
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(open(filename, 'rb').read())
encoders.encode_base64(attachment)
attachment.add_header(
'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
msg.attach(attachment)
smtp = smtplib.SMTP('localhost')
smtp.sendmail(sender, toaddrs, msg.as_string())
logger.info('Email have sent successfully!')
smtp.quit()
任何帮助将不胜感激。 谢谢
通过附件解决这个问题,然后附上消息。
def send_mail(subject, sender, recipient, cc, toaddrs, body, filename):
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = ", ".join(recipient)
msg['Cc'] = ", ".join(cc)
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(open(filename, 'rb').read())
encoders.encode_base64(attachment)
attachment.add_header(
'Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
msg.attach(attachment)
message = MIMEText(body, 'html') # html.read(), 'html')
msg.attach(message)
smtp = smtplib.SMTP('localhost')
smtp.sendmail(sender, toaddrs, msg.as_string())
logger.info('Email have sent successfully!')
smtp.quit()