DigitalOcean notes

From raju

referral link

If you sign up to a digital ocean account using http://www.digitalocean.com/?refcode=baae903dc724 , you get $10 and I get $25. Go ahead and make me rich! ;)

using smtp.gmail.com to send emails from a digitalocean droplet

Create a config file

    $ cat config.py
    fromaddr = "foo@gmail.com"
    password = "bar"
    toaddr = "baz@gmail.com"
    

Restrict the permissions on it as it contains your password.

    $ chmod 600 config.py
    

Basic script to send emails

    $ cat basic_email.py
    import smtplib
    import config
    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.ehlo()
    server.starttls()
    server.login(config.fromaddr, config.password)
    msg = "Subject: Be nice.\nSome nice msg."
    server.sendmail(config.fromaddr, config.toaddr, msg)
    server.quit()
    

Send email

    $ python3 ./basic_email.py
    

This will fail for the first time with an SMTPAuthenticationError exception.

Now login into the config.fromaddr gmail account -> open the email from Google with Subject "Review blocked sign-in attempt" -> click link under "allowing access to less secure apps" -> set "Allow less secure apps:" to ON

If this is successful, google will send a new email with Subject "Access for less secure apps has been turned on".

Now go to https://accounts.google.com/DisplayUnlockCaptcha -> click the "Continue" to "Allow access to your Google account"

Now, if you run the python program again, it should run successfully and send an email to the config.toaddr in the config file.

Ref:-