Errors sending and receiving emails

Hey guys,

I have setup a custom email domain on my ERPNext and setup a few email addresses for sending and receiving emails. However, I’m getting these errors in my error logs:

First Error
Error Title: Error

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 732, in append_email_to_sent_folder
    email_server.imap.append("Sent", "\\Seen", imaplib.Time2Internaldate(time.time()), message.encode())
AttributeError: 'bytes' object has no attribute 'encode'

Another Error that I get for every email address that I have created:

Second Error
Error Title: Error while connecting to email account Support

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 287, in receive
    email_server = self.get_incoming_server(in_receive=True, email_sync_rule=email_sync_rule)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 173, in get_incoming_server
    self.check_email_server_connection(email_server, in_receive)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 186, in check_email_server_connection
    email_server.connect()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/receive.py", line 42, in connect
    return self.connect_imap()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/receive.py", line 50, in connect_imap
    self.imap = Timed_IMAP4_SSL(self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout"))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/receive.py", line 561, in __init__
    self._super.__init__(self, *args, **kwargs)
  File "/opt/bitnami/python/lib/python3.7/imaplib.py", line 1288, in __init__
    IMAP4.__init__(self, host, port)
  File "/opt/bitnami/python/lib/python3.7/imaplib.py", line 198, in __init__
    self.open(host, port)
  File "/opt/bitnami/python/lib/python3.7/imaplib.py", line 1301, in open
    IMAP4.open(self, host, port)
  File "/opt/bitnami/python/lib/python3.7/imaplib.py", line 299, in open
    self.sock = self._create_socket()
  File "/opt/bitnami/python/lib/python3.7/imaplib.py", line 1293, in _create_socket
    server_hostname=self.host)
  File "/opt/bitnami/python/lib/python3.7/ssl.py", line 423, in wrap_socket
    session=session
  File "/opt/bitnami/python/lib/python3.7/ssl.py", line 870, in _create
    self.do_handshake()
  File "/opt/bitnami/python/lib/python3.7/ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/rq/timeouts.py", line 64, in handle_death_penalty
    '({0} seconds)'.format(self._timeout))
rq.timeouts.JobTimeoutException: Task exceeded maximum timeout value (300 seconds)

I have tested these email accounts on IMAP outside of ERPNext and they work fine. Anyone knows what’s causing this?

Thank you.

try: bench enable-scheduler , and look at the error logs

HI @smino I installed ERPNext using Docker and is on production. I remember because I during the installation, the docs said I didn’t need bench for ERPNext. Now when I see the commands, I’m afraid it would overwrite my instance altogether. Is there a safe way to do this?

My knowledge of Docker is limited. First and foremost a backup should be made of your image so if something does happen you can revert to an earlier instance. @revant_one may have a suggestion for that. As far as I know Bench is an integral part of ERPNext and familiarization with the commands is essential for successful maintenance. The bench enable-scheduler is not likely to cause any problems.

bench cli is a wrapper that makes bench_helper.py from frappe user friendly.

bench cli also does supporting things like nginx and supervisor setup, config setup etc.

In production docker images there is no bench cli installed.

the only bench commands it contains is from frappe’s bench_helper.py.

Speaking of enable-scheduler, it is part of “framework commands”, it is available in production docker containers.

Run bench --help to know available commands

Hi @smino and @revant_one

Thanks a lot for replying and assisting me on this. I think I forgot to include the most obvious thing that I was getting. When I type any bench command, I get the following:

Command 'bench' not found, but can be installed with:
apt install ruby-active-model-serializers  

Which led me to my answer above. I don’t have bench with my production docker instance which kinda confirms what @revant_one was suggesting. Is it safe to install bench on production machine? And what’s the best method to go about with this?

bench is required in case of non docker install.

bench is not installed in docker containers because with bench ERPNext images size goes up to 3GB+.

If you are using non-docker install, easy_install or manual install, then bench is required.

Hey @revant_one, sorry for being MIA, was in a lockdown with no internet :sob:

So since I’m using docker, what should I do to get the output similar to bench enable-scheduler ?

bench enable-scheduler is available in container

❯ docker run -it frappe/frappe-worker:develop bench --help
Usage: bench frappe [OPTIONS] COMMAND [ARGS]...

Options:
  --site TEXT
  --profile    Profile
  --verbose    Verbose
  --force      Force
  --help       Show this message and exit.

Commands:
  add-system-manager          Add a new system manager to a site
  add-to-email-queue          Add an email to the Email Queue
  add-to-hosts                Add site to hosts
  backup                      Backup
  browse                      Opens the site on web browser
  build                       Minify + concatenate JS and CSS files, build...
  build-message-files         Build message files for translation
  build-search-index
  bulk-rename                 Rename multiple records via CSV file
  clear-cache                 Clear cache, doctype cache and defaults
  clear-website-cache         Clear website cache
  console                     Start ipython console for a site
  data-import                 Import documents in bulk from CSV or XLSX...
  destroy-all-sessions        Clear sessions of all users (logs them out)
  disable-scheduler           Disable scheduler
  disable-user
  doctor                      Get diagnostic info about background workers
  drop-site
  enable-scheduler            Enable scheduler
  execute                     Execute a function
  export-csv                  Export data import template with data for...
  export-doc                  Export a single document to csv
  export-fixtures             Export fixtures
  export-json                 Export doclist as json to the given path, use...
  get-untranslated            Get untranslated strings for language
  import-csv                  Import CSV using data import
  import-doc                  Import (insert/update) doclist.
  import-translations         Update translated strings
  install-app                 Install a new app to site, supports multiple...
  jupyter
  list-apps                   List apps in site
  make-app                    Creates a boilerplate app
  mariadb                     Enter into mariadb console for a given site.
  migrate                     Run patches, sync schema and rebuild...
  migrate-to                  Migrates site to the specified provider
  new-language                Create lang-code.csv for given app
  new-site                    Create a new site
  ngrok
  partial-restore
  postgres                    Enter into postgres console for a given site.
  publish-realtime            Publish realtime event from bench
  purge-jobs                  Purge any pending periodic tasks, if event...
  ready-for-migration
  rebuild-global-search       Setup help table in the current site (called...
  reinstall                   Reinstall site ie.
  reload-doc                  Reload schema for a DocType
  reload-doctype              Reload schema for a DocType
  remove-from-installed-apps  Remove app from site's installed-apps list
  request                     Run a request as an admin
  reset-perms                 Reset permissions for all doctypes
  restore                     Restore site database from an sql file
  run-patch                   Run a particular patch
  run-tests                   Run tests
  run-ui-tests                Run UI tests
  schedule
  scheduler
  serve                       Start development web server
  set-admin-password          Set Administrator password for a site
  set-config                  Insert/Update a value in site_config.json
  set-last-active-for-user    Set users last active date to current datetime
  set-maintenance-mode
  show-config                 print configuration file
  show-pending-jobs           Get diagnostic info about background jobs
  start-recording
  stop-recording
  trigger-scheduler-event     Trigger a scheduler event
  uninstall-app               Remove app and linked modules from site
  update-translations         Update translated strings
  use                         Set a default site
  version                     Show the versions of all the installed apps
  watch                       Watch and concatenate JS and CSS files as and...
  worker

Hi there,

Did I do this correctly?

root@localhost:~# docker run -it frappe/frappe-worker:develop bench enable-scheduler
Please specify --site sitename
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 18, in <module>
    [sys.executable, bench_helper, 'frappe'] + sys.argv[1:],
  File "/usr/local/lib/python3.7/subprocess.py", line 363, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/frappe/frappe-bench/env/bin/python', '/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py', 'frappe', 'enable-scheduler']' returned non-zero exit status 1.
root@localhost:~# docker run -it frappe/frappe-worker:develop bench --site jwerp enable-scheduler
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 99, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 26, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/scheduler.py", line 44, in enable_scheduler
    frappe.init(site=site)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 164, in init
    local.conf = _dict(get_site_config())
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 246, in get_site_config
    raise IncorrectSitePath("{0} does not exist".format(local.site))
frappe.exceptions.IncorrectSitePath: 404 Not Found: jwerp does not exist
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 18, in <module>
    [sys.executable, bench_helper, 'frappe'] + sys.argv[1:],
  File "/usr/local/lib/python3.7/subprocess.py", line 363, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/frappe/frappe-bench/env/bin/python', '/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py', 'frappe', '--site', 'jwerp', 'enable-scheduler']' returned non-zero exit status 1.
root@localhost:~#

Check this frappe_docker/site-operations.md at main · frappe/frappe_docker · GitHub