Difficulty Setting up Email Domain - non-standard IMAP or POP3 port

What do I do when my email server uses non standard IMAP or POP3 ports?
I do not see a way in the user interface to set them. The only port setting available is for the SMTP server.


@aleksas kindly reported that issue on github Unusable pop/imap with custom port

@clarkej Yes, I see where he did in fact report the issue here on the forum and at github, but still, there is an eerie silence surrounding the issue.

I don’t really care at this point if there is a bug in the system or a missing user interface part. I just want a way to brute force my odd port numbers into the mail module.

I was hoping someone here might be able to tell me how I might edit a file to use my ports on this particular installation. The scary thing is the silence. Like crickets… it makes me think we don’t really have an email module expert around.


Based on this https://docs.python.org/2/library/imaplib.html

you might try to change the code here?https://github.com/frappe/frappe/blob/develop/frappe/email/doctype/email_domain/email_domain.py

So for example with this:

 test = imaplib.IMAP4_SSL(self.email_server)

just append the port number like so:

someportotherthan993 = '1993'
test = imaplib.IMAP4_SSL(self.email_server, someportotherthan993)

My guess is that these are the default ports

Port 110 - this is the default POP3 non-encrypted port
Port 995 - this is the port you need to use if you want to connect using POP3 securely

Port 143 - this is the default IMAP non-encrypted port
Port 993 - this is the port you need to use if you want to connect using IMAP securely

Here are more notes https://www.fastmail.com/help/technical/ssltlsstarttls.html

Laughing to myself here… I sure am glad to have folks like you around. You had the the idea of where to look for the usage syntax to see if it could be hijacked and used to this advantage. Very cool. :sunglasses:

Thanks for the suggestion. I will spin up one of my Google Cloud staging servers and start testing that idea tonight.


@bkm Actually what I did to get around the custom port issue was to add port redirection to erpnext machine.

To do that (on Debian Linux) add /etc/init.d/redir.imap (chmod 0755, change redir.imap as you see fit) script:
(replace uppercase terms with suitable values)

#! /bin/sh
# /etc/init.d/redir.imap

# The following part always gets executed.
echo "Redirect local port 993 to IMAP_SERVER_ADDRESS:CUSTOM_PORT"

redir  --lport=993  --laddr= --cport=CUSTOM_PORT --caddr=IMAP_SERVER_IP_ADDRESS &

Afterwards setup erpnext for imap to be directed to localhost.
Also change 993 to whichever port erpnext expects.


Again… Thank you! I am happy to see that the creative solutions of others are still available to us lesser creative users.

I think I like this approach better than actually editing my python scripts.