4
因此,我正在按照python發送電子郵件的教程,問題在於它是爲Python 2而不是python 3編寫的(這是我的)。所以這裏是我想要得到答案什麼是在Python 3中的電子郵件模塊?我想要得到的是具體的模塊是:python 3中的電子郵件模塊
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMETex
我也有一個feelling,當我得到了這個模塊會出現錯誤(沒有到達那裏又因爲 的模塊上方給錯誤
import smtp
這裏是腳本:
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMETex
fromaddr = ("[email protected]")
toaddr = ("[email protected]")
msg = MIMEMultipart
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = ("test")
body = ("This is a test sending email through python")
msg.attach(MIMEText(body, ('plain')))
import smptlib
server = smptlib.SMPT('mail.mchsi.com, 456')
server.login("[email protected]", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
text = msg.as_string()
sender.sendmail(fromaddr, toaddr, text)
那些位於'email.mime':http://docs.python.org/3.3/library/email.mime.html#module-email.mime – michaelmeyer
@ doukremt是的,這解決了我的問題,但現在得到這個錯誤Traceback(最近調用最後): 文件「C:\ Python33 \ emailtest.py」,第9行,在 msg ['From'] = fromaddr TypeError:'類型「對象不支持項目分配 –
@ raspberry.pi您將'msg'分配給'MIMEMultipart'類,它是類。你忘了括號:msg = MIMEMultipart()' – andersschuller