2

嗨,我编写了一个 Python 脚本来发送一条简单的消息。该脚本适用于我的大学电子邮件地址。但是,使用 gmail 似乎存在问题。我尝试使用我的电子邮件并仅以登录名登录 - 结果相同。我得到的错误是:

Error 252 : b"2.1.5 Send some mail, I'll try my best f18sm1267047wiv.14"

我不确定我做错了什么。我真的找不到太多信息。我得到的只是上面的行,没有别的。我在 Linux 机器上运行脚本,它是在 linux 机器上编写的。

#! /usr/bin/python3.1

def sendmail(recepient,  msg):

    import smtplib

    # Parameters
    sender = 'login@gmail.com'
    password = 'password'
    smtpStr = 'smtp.gmail.com'
    smtpPort = 587
    # /Parameters

    smtp_serv = smtplib.SMTP(smtpStr, smtpPort)
    smtp_serv.ehlo_or_helo_if_needed()
    smtp_serv.starttls()
    smtp_serv.ehlo()

    recepientExists = smtp_serv.verify(recepient)
    if recepientExists[0] == 250:
        smtp_serv.login(sender, password)
        try:
            smtp_serv.sendmail(sender, recepient, msg)
        except smtplib.SMTPException:
            print(recepientExists[1])
    else:
        print('Error',   recepientExists[0], ':',  recepientExists[1])

    smtp_serv.quit()

sendmail('receiver@gmail.com',  'hi')
4

1 回答 1

-1

这很简单。没有人支持 VRFY,因为它非常有助于垃圾邮件。拉出那张支票,它应该可以正常工作。

于 2011-11-08T17:51:50.120 回答