我正在尝试将电子邮件从我的正式ID自动发送到另一个正式ID。为此,我使用了以下python脚本。
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
fromaddr = "<SENDER MAIL ID>"
toaddr = "<RECIPIENT MAIL ID>"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "SUBJECT OF THE MAIL"
body = "Robot Uprising, We are coming for you"
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "YOUR PASSWORD")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
执行此操作时,我面临以下问题:
Traceback (most recent call last):
File "mailsendtest.py", line 2, in <module>
from email.MIMEMultipart import MIMEMultipart
ImportError: No module named MIMEMultipart
我是python的入门者。请提供输入。谢谢!
答案 0 :(得分:0)
假设您使用的是Python3,我发现您的imports
存在两个问题。
将from email.MIMEMultipart import MIMEMultipart
更改为from email.mime.multipart import MIMEMultipart
将from email.MIMEText import MIMEText
更改为from email.mime.text import MIMEText
如果这些库不起作用,请确保已安装这些库。