简体   繁体   English

Smtplib不起作用

[英]Smtplib doesn't Work

I got the script from the first example here: https://docs.python.org/2/library/email-examples.html#email-examples 我从这里的第一个示例获得了脚本: https : //docs.python.org/2/library/email-examples.html#email-examples

I made sure there is no file name similar to email.py. 我确保没有类似于email.py的文件名。

 import smtplib # Import the email modules we'll need from email.mime.text import MIMEText fp = open(textfile, 'rb') # Create a text/plain message msg = MIMEText(fp.read()) fp.close() # me == the sender's email address # you == the recipient's email address msg['Subject'] = 'The contents of %s' % textfile msg['From'] = torontocoinowl@gmail.com msg['To'] = torontocoinowl@gmail.com # Send the message via our own SMTP server, but don't include the # envelope header. s = smtplib.SMTP('localhost') s.sendmail(me, [you], msg.as_string()) s.quit() 

The error is 错误是

 C:\\Users\\donald\\AppData\\Local\\Programs\\Python\\Python35-32\\python.exe C:/Users/donald/PycharmProjects/untitled3/testingemail/ff.py Traceback (most recent call last): File "C:/Users/donald/PycharmProjects/untitled3/testingemail/ff.py", line 1, in <module> import smtplib File "C:\\Users\\donald\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\smtplib.py", line 47, in <module> import email.utils File "C:\\Users\\donald\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\email\\utils.py", line 28, in <module> import random File "C:\\Users\\donald\\PycharmProjects\\untitled3\\random.py", line 1 From random import randint ^ SyntaxError: invalid syntax Process finished with exit code 1 

You are having a file random.py in your folder. 您的文件夹中有一个文件random.py It clashes with the random modul in Python. 它与Python中的随机模块冲突。 Remove of rename that file! 删除重命名该文件!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM