编辑新问题的问题 我能够收到电子邮件但这是服务器端的延迟。**
我正在编写非常小的应用程序,用于在 python 中发送带有 excel 文件附件的电子邮件。它包含多个工作表,每个工作表都包含图表。我收到了电子邮件,但看起来文件已损坏。是否可以附加包含图形的 Excel(大小也高达 2MB)
# -*- coding: iso-8859-1 -*-
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
import smtplib,email,email.encoders,email.mime.text,email.mime.base
msg = MIMEMultipart()
msg['Subject'] = 'Email From Python Abhishek'
msg['From'] = 'xyz.com'
msg['To'] = 'abc.com'
fileMsg = email.mime.base.MIMEBase('application','vnd.ms-excel')
fileMsg.set_payload(file('Final.xlsx').read())
email.encoders.encode_base64(fileMsg)
fileMsg.add_header('Content-Disposition','attachment;filename=Final.xlsx')
msg.attach(fileMsg)
smtp = SMTP("email exchange server",25)
#(I was able to connect with exchange server using Telnet http://www.exchangeinbox.com/article.aspx?i=93)
# Start the server:
smtp.ehlo()
I have commented below code as per one internet posting. it suggest that if you
are sending internal Email you may not require login and password.I also do not
want to write password as it is violate company policy
if I remove comment from line. it give me error for bad authentication.
#smtp.login("abc", "password")
smtp.sendmail(msg['From'],msg['To'],msg.as_string())
#server.quit()