openpanel/documentation/docs/articles/user-experience/setup-remote-smtp-server-for-openpanel.md
2024-08-25 16:10:09 +02:00

2.1 KiB

Setup Remote SMTP Server for OpenPanel

To set up a remote SMTP server for all emails sent from OpenPanel user websites, follow these steps:

Whitelist the Remote SMTP Server

On the server with OpenPanel installed, ensure that the IP address of the remote SMTP server is whitelisted on firewall.

Similarly, on the remote SMTP server, make sure to whitelist the IP address of the OpenPanel server.

Configure SMTP per User

For each user, SMTP settings are configured via the /etc/msmtprc file. An example file content is shown below:

# /etc/msmtprc
defaults
auth       off
tls        off
logfile    /var/log/msmtp.log

account    default
host       openadmin_mailserver
port       25
from       USERNAME@HOSTNAME

Login as root for that user and edit the file. In this file, set the email address and server to be used for all outgoing emails.

For example, you can configure Gmail SMTP settings as shown in the Arch Linux Wiki.

After saving the configuration, test sending emails from a PHP website like WordPress or directly from the terminal.

Configure SMTP for all existing users

Create a new file on the server, and in it copy the default /etc/msmtprc file.

In the file set your remote SMTP server address and optionally logins.

When finished, run the bellow command to copy the file to each OpenPanel user:

  for user in $(opencli user-list --json | grep -v 'SUSPENDED' | awk -F'"' '/username/ {print $4}'); do
    echo "Processing user: $user"
    docker cp filename $user:/etc/msmtp
  done

Configure SMTP automatically for new users

To automatically have all users pre-configured to use your remote SMTP server, build a docker image that has your custom /etc/msmtprc file.