python AttributeError:模块'smtplib'没有属性'SMPT'

时间:2016-03-16 17:46:10

标签: python string email file-io

我是一名蟒蛇初学者,我想从你那里得到一些帮助。 最近我写了一个关于电子邮件垃圾邮件(从配置文件中检索数据)的程序,使用'smtp'模块,我不能很好地使用它,所以当我运行程序时,它说:

enter any key to exit
enter 'spam' to spam an email
Enter: spam
Running..Running..Running..Running..Running..Running..Running..Traceback  (most recent call last):
File "C:\Users\Leon\Desktop\Progetti\Gdaze\Gdaze.py", line 61, in <module>
emailSetupAndGo(getData()[0], getData()[1], getData()[2], getData()[3], getData()[4], getData()[5])
File "C:\Users\Leon\Desktop\Progetti\Gdaze\Gdaze.py", line 46, in emailSetupAndGo
server = smtplib.SMPT('smtp.gmail.com:587')
AttributeError: module 'smtplib' has no attribute 'SMPT'

在看到此错误后,我搜索了它,并在stackoverflow上找到了一个解决方案,但它只适用于将文件命名为email.py的人。 在这里你是源代码(我也认为我用.split('')删除空格时出错了)所以你可以告诉我错误是什么:

import smtplib
import sys

def getData():
    #GETTING DATA FROM THE FILE 
    configFile = open('config.txt', 'rt')
    usernameLine = configFile.readline()
    passwordLine = configFile.readline()
    nLine = configFile.readline()
    fromemailLine = configFile.readline()
    toemailLine = configFile.readline()
    msgLine = configFile.readline()
    configFile.close()
    if "<yourgmail's>" in usernameLine:
        sys.stderr.write("NoSettings ERROR: modify the config.txt file    before you run the program.")
    elif "<yourgmail's>" in passwordLine:
        sys.stderr.write("NoSettings ERROR: modify the config.txt file     before you run the program.")
    elif "<int>" in nLine:
        sys.stderr.write("NoSettings ERROR: modify the config.txt file     before you run the program.")
    elif "<youremail>" in fromemailLine:
        sys.stderr.write("NoSettings ERROR: modify the config.txt file     before you run the program.")
    elif "<emailtospam>" in toemailLine:
        sys.stderr.write("NoSettings ERROR: modify the config.txt file     before you run the program.")
    elif "<msg>" in msgLine:
        sys.stderr.write("NoSettings ERROR: modify the config.txt file     before you run the program.")
    else:
        sys.stdout.write("Running..")
        #DECLARING THE MAIN VARIABLES
        u = str(usernameLine[11:])
        pw = str(passwordLine[11:])
        n = str(nLine[27:])
        fromemail = str(fromemailLine[12:])
        toemail = str(toemailLine[10:])
        msg = str(msgLine[10:])
        #DELETING SPACES IN THE FILE TO STORE CORRECTLY THE DATA
        u.split(" ")
        pw.split(" ")
        n.split(" ")
        fromemail.split(" ")
        toemail.split(" ")
        msg.split(" ")
        data = [u, pw, n, fromemail, toemail, msg]
        return data

def emailSetupAndGo(n, username, password, fromemail, toemail, message):
    server = smtplib.SMPT('smtp.gmail.com:587')
    server.starttls()
    server.login(username, password)
    for i in n:
        server.sendmail(fromemail, toemail, message)
    server.quit()

def help():
    sys.stdout.write("enter any key to exit\nenter 'spam' to spam an email\n")

while True:
    help()
    entered = input("Enter: ")
    if entered == 'spam':
        getData()
        emailSetupAndGo(getData()[0], getData()[1], getData()[2], getData()[3], getData()[4], getData()[5])
    else:
        break

这里是配置文件:

username = <yourgmail's>
password = <yourgmail's>
number of emails to spam = <int> 
fromemail = <youremail>
toemail = <emailtospam>
message = <msg>

0 个答案:

没有答案