Encryption key x smtp email

Hi,

Somebody can help me to figure out where is the error?

I’m trying do fix it… checked all my e-mail accounts.

Got this error:

Title
frappe.email.queue.flush

Error

{‘event’: u’all’, ‘retry’: 0, ‘log’: <function log at 0x7fc2645ea8c0>, ‘site’: u’bench-manager.local’, ‘job_name’: u’frappe.email.queue.flush’, ‘method_name’: u’frappe.email.queue.flush’, ‘method’: <function flush at 0x7fc264588050>, ‘user’: u’Administrator’, ‘kwargs’: {}, ‘is_async’: True}
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py”, line 103, in execute_job
method(**kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 341, in flush
check_email_limit()
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 232, in check_email_limit
smtp_server = SMTPServer()
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/smtp.py”, line 167, in init
self.setup_email_account(append_to)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/smtp.py”, line 170, in setup_email_account
self.email_account = get_outgoing_email_account(raise_exception_not_set=False, append_to=append_to, sender=sender)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/smtp.py”, line 82, in get_outgoing_email_account
email_account = get_default_outgoing_email_account(raise_exception_not_set=raise_exception_not_set)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/smtp.py”, line 117, in get_default_outgoing_email_account
email_account.password = email_account.get_password(raise_exception=False)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 648, in get_password
return get_decrypted_password(self.doctype, self.name, fieldname, raise_exception=raise_exception)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/password.py”, line 47, in get_decrypted_password
return decrypt(auth[0][0])
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/password.py”, line 150, in decrypt
frappe.throw(_(‘Encryption key is invalid, Please check site_config.json’))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 339, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 325, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 298, in _raise_exception
raise raise_exception(msg)
ValidationError: Encryption key is invalid, Please check site_config.json

Somebody can help me to fix it?

Hi, from my experience that error can occurs after database restore.
so did you recently restore database to a new server?
or did you change anything in the file site_config.json?

Yes, I had to restore… Have I mess something?

I had bench.manager with a different encryption key of my site. I don’t know if I change it on my site will make it work. The bench.manager is chmod locked.

Hi @xickomesquita

Did you restore to a different server? If so, you need to copy the encryption key in the site_config.json file on the old server and use that to replace the encryption key on the new server

Cheers

1 Like

No you have not messed anything. there is a file called site_config.json it is in directory

~frappe-bench/sites/site1.local/site_config.json

That file has it has encryption keys in it. so if you still have access to your previous instance, go to that directory copy the encryption keys and paste them on your new instance in the same file site_config.json

Yes that’s the correct solution.
As I faced the same issue when backing up one of my instance and restoring.

But i would like to know if there is any way to restore if the encryption is lost?

There is no other way. At-least none that I know of.
You will be able to restore but some features (like email) won’t work without original encryption keys

The site_config.json is included on the backup?

Thanks!!

1 Like

No its not included in backup.
Since it’s not safe to have backup and encryption keys both in one place

1 Like

So… I don’t know were to get it… I have 2 keys… One in my site, and other in the bench-manager… When I use the bench-manager, it doesn’t work, and I got the alert “Encryption key is invalid…” like. When I use the site_config, everything works fine, but the email doesn’t work anymore…

what you need is the original encryption keys which come from the server instance where you took that backup from.
so if you still have access to that previous instance, go to this file and copy the encryption keys

frappe-bench/sites/site1.local/site_config.json

paste them in the same file of your new server instance

One last question: What if I delete the encrypt key from config.json? I did it, and the system is still working…

from personal experience I noticed that some features won’t work without encryption keys. So you might have to try testing out all the modules you use to be sure if everything works.

You are right. It doesn’t work. Still trying!!

1 Like

I believe I did the trick!

  1. delete encrypt key from config.json
  2. delete all the e-mail setup
  3. input the e-mail server
  4. input the e-mail account
    4.1) input the original password from smtp server (i’m using SES from AWS) (it will insert a new encrypt key on your config.json file)
  5. change the password to a new psswd from SES service

voilá!

Now, I get the e-mails… the error is still there… Next try…

The solution is here. I had just reset the password for the Email accounts and it worked as I only had 1 email account configured.

In my case, it is the partial solution!!

Now, i’ve got 554 error from SES…

Thanks!

That seems like email address verification issue based on this aws support url.

Done. I had to input all the e-mails, and then, delete all the unsent e-mail queue. Now, all the e-mails are ok!

1 Like