0

I'm trying to setup yagmail with an external .yagmail file with credentials but when I run the code it returns

YagInvalidEmailAddress: Emailaddress "yagmail.register('my.username@gmail.com', 'my.password')" is not valid according to RFC 2822 standards

the .yagmail file is like this

yagmail.register('my.username@gmail.com', 'my.password')

Any suggestion?

Andrea Angeli
  • 131
  • 1
  • 16

1 Answers1

0

You should run the following once in python, which will store the registration in the backend (yagmail.register is just a wrapper around keyring lib functionality):

import yagmail

yagmail.register(email, pwd)

After this, you can just use the following in your script to start using yagmail:

yag = yagmail.SMTP(email)
yag.send()

If you want to omit the email as well, you can write your gmail address in the .yagmail file, which should reside in you $HOME directory.

Then, you could just use:

yag = yagmail.SMTP()
yag.send()

On some systems (CentOS for me), you also need to pip install keyrings.alt and import keyrings in your registration script.

rouhija
  • 241
  • 2
  • 8