There are several possible solutions to this problem, and they're all fairly complex. This is the most transparent configuration I could think of, but honestly I would switch hosts if their SMTP service is unreliable. There are a lot of good, cheap providers of mail services. Also, consider using IMAP instead of POP3, as it will alleviate issues with synchronization likely to arise from such a setup.
The solution is complicated because of the necessary coupling between a Mail Transfer Agent (MTA) and a Mail Delivery Agent (MDA). In order for an email to exist on the POP3 server (the MDA), it must have been delivered through the unreliable SMTP server (the MTA). Your MTA can't store messages on the remote MDA, and the remote MTA can't send messages to your MDA. Without complete synchronization of messages in both directions, intra-company email (the "sending between e-mail addresses on our domain" part) sent from the office will only be stored on the local MDA. This means that users working away from the office would not receive internal emails when checking the hosted POP3 account.
You will need at minimum:
- MTA for SMTP - Courier is the default for CentOS and a good choice
- Firewall (for IP/port redirection) - netfilter or rinetd will work
- MDA and Proxy for POP3/IMAP accounts - Perdition is probably best, Courier has this functionality
Local MTA for Backup SMTP
Add your mail host's SMTP server (the remote MTA) in
/etc/courier/esmtproutes (or wherever that file gets installed on CentOS) to make Courier forward all messages to it. When your host's SMTP is down, the local MTA will queue outbound mail and retry delivery to the remote MTA at a configurable interval.
Configure your firewall to forward all outbound traffic on port 25 to your local MTA.
You can implement only the above for the simplest configuration. It would not allow internal email to continue as normal, but it would make the remote MTA downtime less noticeable
Local MTA with Hosted Domain
Add your company domain as a hosted domain for Courier (the local MTA) in
/etc/courier/hosteddomains. This will override the smarthost and deliver messages according to the configured routing rules. See makehosteddomains and Transport Modules for more information.
Local MDA and Proxy
This can be implemented in many ways, but for example:
- Keep a local copy of email account credentials and use them to authenticate users to the local MDA, which could by default deliver to a "Local" folder for each user account
- Use courier-authlib/authpipe or Perdition to relay those credentials to the remote MDA at the same time, comprising the rest of the folders
- Set up a cron job to retry sending new messages in the "Local" folder to the remote MTA when the SMTP service is up
...Or implement internal DNS and:
- Change MX preferences on the company domain, routing everything to both MTAs (would technically require two internal MTAs)
- Just use a different (even fake) domain name for intra-office emails, and implement it as a failover system