Local Exchange with Secure Mail Gateway
Connecting a local (on-premises) Exchange server via the Secure Mail Gateway (SMG) can fail at several points. This article describes common causes and how the connection can be checked step by step.
Device requests take the following route: device → reverse proxy at the SMG Service URL → Secure Mail Gateway standalone service → Exchange server. Devices receive the SMG Service URL via policy instead of the Exchange server address. The reverse proxy forwards the path /Microsoft-Server-ActiveSync to the SMG service on port 8093 (smg:8093 for a Docker installation, 127.0.0.1:8093 for a native Linux installation). As of Relution 26.4, only the SMG service connects to the Exchange server, not the Relution server. Up to Relution 26.3, the Relution server forwarded the requests itself; this article describes the setup as of 26.4.
Setting up the service is described under Installing Secure Mail Gateway →, the settings in Relution under Secure Mail Gateway →.
Checking the settings
Common causes of errors lie in the settings of the respective organization under Settings → Device Management → Secure Mail Gateway:
- Exchange URL: the address at which the SMG service reaches the Exchange server.
- SMG Service URL: the publicly reachable address at which the reverse proxy forwards
/Microsoft-Server-ActiveSyncto the SMG service. Devices receive this address as their server. - Exchange domain: If set, the SMG prefixes it to the user name when signing in to the Exchange server (
DOMAIN\user). - Custom exchange host header and Exclude port from exchange host header: determine the host header the SMG sends to the Exchange server.
- Allowance rules and Allowance for unknown devices: Devices that do not meet these rules are rejected. Restrictions are therefore best configured only after the connection has been tested successfully.
In addition, the option Use Secure Mail Gateway must be enabled in the Exchange configuration of the policy.
Analyzing the reverse proxy log
The access log of the reverse proxy (e.g. nginx) is needed for further analysis:
- Linux:
/var/log/nginx/relution_access.log - Windows: in the respective nginx installation path, e.g.
/nGinx/logs/relution_access.log
If mails are retrieved on the device, the log must contain entries for the URL /Microsoft-Server-ActiveSync.
Such an entry only shows that the device’s request reached the reverse proxy. Whether it succeeded is shown by the HTTP status code in the entry: 200 means success. Individual 401 entries are normal, because the SMG answers requests without credentials with 401 and thereby prompts the device to sign in (Windows devices, for example, first send a request without user name and password). If the status remains 401 or other error codes such as 403, 404 or 5xx appear, the request was rejected or not forwarded correctly.
Troubleshooting
If nothing is written to the log, a browser can be used to check whether the address is generally reachable:
https://<SMG Service URL>/Microsoft-Server-ActiveSync
If the request reaches the SMG service, the browser prompts for credentials, because the SMG answers requests without credentials with 401. The request must also leave an entry in the reverse proxy log.
- If no entry is generated, the infrastructure must be checked.
- If the entry can be found, the settings of the Exchange configuration in the Relution policy or the SMG settings are probably not set correctly or are invalid.
Checking the connection
A curl command on the host of the Secure Mail Gateway service can be used to check the connection from the SMG to the Exchange server. As with the SMG, the Exchange domain precedes the user name; if no Exchange domain is set in the SMG settings, it is omitted:
curl https://outlook.XXX.de/Microsoft-Server-ActiveSync --user "EXCHANGE-DOMAIN\user@domain.com:password" --verbose --http1.1 -i
The output may show a certificate error, for example:
Trying 172.16.105.109:443...
Connected to outlook.XXX.de (172.000.000.000) port 443 (#0)
schannel: disabled automatic use of client certificate
ALPN: offers http/1.1
schannel: SEC_E_UNTRUSTED_ROOT (0x80090325) - The certificate chain was issued by an untrusted certificate authority.
Closing connection 0
curl: (60) schannel: SEC_E_UNTRUSTED_ROOT (0x80090325) - The certificate chain was issued by an untrusted certificate authority.
More details here: https://curl.se/docs/sslcerts.html
Trusting the CA certificate
If the error message is displayed as above, the root certificate of the CA that issued the Exchange certificate is not stored as trusted. The SMG does not use the operating system’s certificate store for this, but the certificates of its Java runtime. The CA certificate must therefore be placed, PEM-encoded, in a directory that is mounted into the SMG container at /opt/app/ca-certs (e.g. ./smg/ca-certs:/opt/app/ca-certs:ro). The container must then be restarted, because the directory is only read at startup. This feature requires an SMG image of version 26.0.3 or later; the recommended tag latest includes it.
(Optional) Trusting a custom CA certificate →
Whether the SMG trusts the certificate is shown in the log of the SMG container (docker logs smg). At startup, the SMG logs every CA certificate it loads (Trusting custom CA certificate from …). If it rejects the Exchange server’s certificate chain, it logs a warning with the chain presented by the server (Server certificate chain rejected for …) and names the likely cause, such as a missing CA certificate or an incomplete certificate chain.
Reading the HTTPS communication
The HTTPS communication between the SMG and the Exchange server can be traced in the log of the SMG container. To do this, the following section is added to smg/application.yaml:
logging:
level:
io.relution: DEBUG
org.apache.hc.client5.http.wire: DEBUG
The smg container must then be restarted, e.g. with docker compose restart smg. The log level of the SMG container cannot be changed via the Relution system portal, and the SMG container log is not part of the Relution log file. The logs are shown by docker logs smg. Further information is available under Troubleshooting →.
Communication must be triggered by the device to fill the log with hints about the cause. The wire log contains the complete requests, including the credentials. After the analysis, the log level is therefore set back to INFO or the org.apache.hc.client5.http.wire entry is removed, and the container is restarted again.
Evaluating the log
The SMG container log can then be searched for conspicuous clues. For example, if the user name or password is incorrect, the sign-in fails and the Exchange server responds with 401 Unauthorized. The transmitted credentials are Base64-encoded in the Authorization: Basic … header, e.g. dGVzdHVzZXI6NDcxMQ==.
This value can be decoded in the browser console to compare the user name and password. If an Exchange domain is set, the decoded user name starts with the domain.
atob('dGVzdHVzZXI6NDcxMQ==')
