kootenpv / yagmail

Send email in Python conveniently for gmail using yagmail
MIT License
2.66k stars 265 forks source link

smtplib.SMTPServerDisconnected: Server not connected #48

Closed xThuby closed 8 years ago

xThuby commented 8 years ago

Getting error mentioned in title. Someone please help.

code:

#!/usr/bin/env python3

import yagmail

from hackerutils import get_dotenv

dotenv = get_dotenv()

GMAIL_USERNAME = dotenv['GMAIL_USERNAME']
GMAIL_PASSWORD = dotenv['GMAIL_PASSWORD']

yagmail.register(GMAIL_USERNAME, GMAIL_PASSWORD)

def main():
    yag = yagmail.SMTP(GMAIL_USERNAME)
    yag.send(
        'oliver.252@hotmail.com',
        'testing',
        'This is a fucking test you BITCH!',
        )

if __name__ == '__main__':
    main()
kootenpv commented 8 years ago
  1. You should only have to run yagmail.register once
  2. I suspect you perhaps still have to allow smtplib to send emails (in your gmail)?
  3. On the line ...BITCH!', that comma should not be there.

Other than that, nothing comes to mind... did you ever get it working? Try upgrading yagmail (pip install -U yagmail), and perhaps try both python2 and python3.

xThuby commented 8 years ago

I followed all your advice (Except trying python2 since I've never used it before, and I don't have pip (Or whatever it is) for python2 so it doesn't recognize yagmail) I'm still getting the same error.

Here's the sourcecode with all of your suggested changes.

#!/usr/bin/env python3

import yagmail

from hackerutils import get_dotenv

dotenv = get_dotenv()

GMAIL_USERNAME = dotenv['GMAIL_USERNAME']
GMAIL_PASSWORD = dotenv['GMAIL_PASSWORD']

def main():
    yag = yagmail.SMTP(GMAIL_USERNAME)
    yag.send(
        'oliver.252@hotmail.com',
        'testing',
        'This is a fucking test you BITCH!'
        )

if __name__ == '__main__':
    main()

Edit: Yagmail is freshly installed so everything is up to date. Still not working.

xThuby commented 8 years ago

Found out the problem. It was the dotenv[GMAIL_PASSWORD] where things went wrong. Just removed that and now it works like a charm!