2
我是Python的新手,因此在使用python腳本發送郵件時遇到了一些困難。我使用mime和smtplib。出於某種原因,我無法發送郵件並且發送郵件沒有任何機構,附上代碼。 任何想法?如何在Python中使用Mimemultipart發送郵件
import smtplib
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
hostname='hello'
sender = '[email protected]'
receivers = ['[email protected]']
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = receivers
msg['Subject'] = "Upgrade started for"+hostname+"."
try:
smtpObj = smtplib.SMTP('mail.xxx.com',25)
smtpObj.sendmail(sender, receivers, msg.as_string())
print "Successfully sent email"
except:
print "Error: unable to send email"
這工作!謝謝 – Vholla