Closed GeorgHo closed 7 years ago
Hi Georg, I think the problem is yagmail is trying to interactively prompt you for you email password. This works during a console session but fails in the context of an Octoprint plugin since there's no terminal prompt available.
Here is how to save your login so yagmail can look it up:
~/OctoPrint/venv/bin/python
import yagmail
yagmail.register('georg@hoXYZ.com', 'PASSWORD')
Hi Jim,
I think this is not the problem or I understand something wrong. I think the problem is the keyring password, on the promt he asks me on the first send for a keyring password "Please enter password for encrypted keyring". In your example you set a password for the mail recipient or must I set there the keyring password?
Thanks for the help Georg
The PASSWORD
in my example represents the SMTP password you need to send email. If your email account needs a password to send mail, you need to register
it or else yagmail will always try to prompt you for it.
If it is a different problem with the keyring or keyring password itself, I suggest you look for help at the yagmail project or the keyring package, because I don't know much more about the authentication process. Do let me know if you figure out a solution.
Hi Jim, the problem is probably Keyring. :-(
When I enter the following:
~/OctoPrint/venv/bin/python -m keyring get yagmail MyMailAccount@gmail.com
Then comes first following prompt:
Please enter password for encrypted keyring:
He prompted for the password that needs Keyring for his decrypt. After entering the password for Keyring, he gives me the password for the SMTP account. I'm going to uninstall everything and see what happens.
Hi Jim, I have not found a solution, Keyring ask for her Keyring_Key to decrypt his file where the passwords are stored and I have no idea where I can store it. Can you tell me where I can enter their login data directly in your code? I will not use keyring.
Sure. Edit your copy of octoprint_emailnotifier/init.py. Look for line 71:
mailer = yagmail.SMTP(user={self._settings.get(['mail_username']):self._settings.get(['mail_useralias'])}, host=self._settings.get(['mail_server']))
Change it to something like this:
mailer = yagmail.SMTP(user="USERNAME", pass="PASSWORD", host="SMTP_SERVER")
Hi Jim, I solved the problem by entered the line in the script. But "pass=" must be named in "password=".
Thank you very much!
Good catch. Glad you got it working!
Hi all, I get this error in the log:
`2016-02-15 19:58:01,490 - py.warnings - WARNING - /usr/lib/python2.7/getpass.py:83: GetPassWarning: Can not control echo on the terminal. passwd = fallback_getpass(prompt, stream)
2016-02-15 19:58:01,491 - octoprint.plugins.emailnotifier - ERROR - Email notification error: Traceback (most recent call last): File "/home/pi/OctoPrint/venv/local/lib/python2.7/site-packages/octoprint_emailnotifier/init.py", line 72, in on_event mailer = yagmail.SMTP(user={self._settings.get(['mail_username']):self._settings.get(['mail_useralias'])}, host=self._settings.get(['mail_server'])) File "/home/pi/OctoPrint/venv/local/lib/python2.7/site-packages/yagmail/yagmail.py", line 68, in init self.login(password) File "/home/pi/OctoPrint/venv/local/lib/python2.7/site-packages/yagmail/yagmail.py", line 178, in login password = self.handle_password(password) File "/home/pi/OctoPrint/venv/local/lib/python2.7/site-packages/yagmail/yagmail.py", line 140, in handle_password password = keyring.get_password('yagmail', self.user) File "/home/pi/OctoPrint/venv/local/lib/python2.7/site-packages/keyring/core.py", line 42, in get_password return _keyring_backend.get_password(service_name, username) File "/usr/local/lib/python2.7/dist-packages/keyrings/alt/file.py", line 79, in get_password password = self.decrypt(password_encrypted).decode('utf-8') File "/usr/local/lib/python2.7/dist-packages/keyrings/alt/file.py", line 290, in decrypt cipher = self._create_cipher(self.keyring_key, data['salt'], File "/home/pi/OctoPrint/venv/local/lib/python2.7/site-packages/keyring/util/properties.py", line 52, in get return self.fget(obj) File "/usr/local/lib/python2.7/dist-packages/keyrings/alt/file.py", line 217, in keyring_key self._unlock() File "/usr/local/lib/python2.7/dist-packages/keyrings/alt/file.py", line 256, in _unlock 'Please enter password for encrypted keyring: ') File "/usr/lib/python2.7/getpass.py", line 83, in unix_getpass passwd = fallback_getpass(prompt, stream) File "/usr/lib/python2.7/getpass.py", line 118, in fallback_getpass return _raw_input(prompt, stream) File "/usr/lib/python2.7/getpass.py", line 135, in _raw_input raise EOFError EOFError`
If I use this in the console, everything works fine and I received a mail; ~/OctoPrint/venv/bin/python import yagmail yagmail.SMTP('XYZ@gmail.com').send('georg@hoXYZ.com', 'Test2', 'Mail von OctoPrint')
What can I do to make it work? Where can I take in the plugin the password for the encrypted keyring?
Thanks for the help Georg