Domanda

Hi I've written a Python script to send a simple message. The script works with my university email address. However, with gmail there seems to be a problem. I've tried using both my email and just login as a login name - same result. The error I get is:

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

I'm not sure what I'm doing wrong. I really couldn't find much info. All I get is the above line, nothing else. I'm running the script on a Linux machine and it was written on a linux machine.

#! /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')
È stato utile?

Soluzione

It's pretty straightforward. Nobody supports VRFY because it's such an aid to spam. Pull out that check and it should work OK.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top