Repository: frappe/frappe

Issue:
Email Account `Password not found` error when using empty password
I have new fresh site with Email Account configured to use localhost and empty password.
I was able to save but worker could not work then.

There is not encrypted password record related to that Email Account (because it was empty) but it is still retrying.

https://github.com/frappe/frappe/blob/master/frappe/model/base_document.py#L593-L597

Here is scheduler log:

> {'retry': 0, 'log': <function log at 0x105e75320>, 'site': u'abc', 'event': u'all', 'method_name': u'frappe.email.queue.flush', 'method': <function flush at 0x105f21488>, 'user': u'Administrator', 'kwargs': {}, 'async': True, 'job_name': u'frappe.email.queue.flush'}
> Traceback (most recent call last):
>   File "/Users/viet/frappe/apps/frappe/frappe/utils/background_jobs.py", line 61, in execute_job
>     method(**kwargs)
>   File "/Users/viet/frappe/apps/frappe/frappe/email/queue.py", line 251, in flush
>     check_email_limit([])
>   File "/Users/viet/frappe/apps/frappe/frappe/email/queue.py", line 143, in check_email_limit
>     smtp_server = SMTPServer()
>   File "/Users/viet/frappe/apps/frappe/frappe/email/smtp.py", line 138, in **init**
>     self.setup_email_account(append_to)
>   File "/Users/viet/frappe/apps/frappe/frappe/email/smtp.py", line 141, in setup_email_account
>     self.email_account = get_outgoing_email_account(raise_exception_not_set=False, append_to=append_to)
>   File "/Users/viet/frappe/apps/frappe/frappe/email/smtp.py", line 62, in get_outgoing_email_account
>     email_account = get_default_outgoing_email_account(raise_exception_not_set=raise_exception_not_set)
>   File "/Users/viet/frappe/apps/frappe/frappe/email/smtp.py", line 90, in get_default_outgoing_email_account
>     email_account.password = email_account.get_password()
>   File "/Users/viet/frappe/apps/frappe/frappe/model/base_document.py", line 597, in get_password
>     return get_decrypted_password(self.doctype, self.name, fieldname, raise_exception=raise_exception)
>   File "/Users/viet/frappe/apps/frappe/frappe/utils/password.py", line 19, in get_decrypted_password
>     frappe.throw(_('Password not found'), frappe.AuthenticationError)
>   File "/Users/viet/frappe/apps/frappe/frappe/__init__.py", line 299, in throw
>     msgprint(msg, raise_exception=exc, title=title, indicator='red')
>   File "/Users/viet/frappe/apps/frappe/frappe/**init**.py", line 292, in msgprint
>     _raise_exception()
>   File "/Users/viet/frappe/apps/frappe/frappe/__init__.py", line 265, in _raise_exception
>     raise raise_exception, encode(msg)
> AuthenticationError: Password not found

If i correct, i'm willing to make a pull request for this fixing. Thanks!



Discussion:

Resolving patch:
diff --git a/frappe/email/smtp.py b/frappe/email/smtp.py
--- a/frappe/email/smtp.py
+++ b/frappe/email/smtp.py
@@ -81,7 +81,7 @@ def get_default_outgoing_email_account(raise_exception_not_set=True):
 	'''
 	email_account = _get_email_account({"enable_outgoing": 1, "default_outgoing": 1})
 	if email_account:
-		email_account.password = email_account.get_password()
+		email_account.password = email_account.get_password(raise_exception=False)
 
 	if not email_account and frappe.conf.get("mail_server"):
 		# from site_config.json


Test patch: