编辑新问题的问题我可以收到电子邮件,但服务器端延迟了。**
我正在写一个非常小的应用程序发送电子邮件与附件excel文件在python。它包含多个工作表,每个工作表都包含图形。我收到了电子邮件,但看起来文件已损坏。 是否可以附加包含图形的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()
这是一个我用gmail账户发送电子邮件的脚本,理论上它应该对其他人有用,但我只测试过gmail。您可以通过main中列出的参数从命令行调用它,也可以直接从另一个Python模块调用mail函数:
如果你有任何问题请告诉我
相关问题 更多 >
编程相关推荐