Set up NGINX IMAP proxy as an MTA between my device and gmail servers
August 10, 2024 02:06PM
Good day everyone!

I have an old device running Windows Mobile 6.5 which means it has expired security certificates. I made it my home project to get this device as "usable" as possible, and part of that is to send/recieve mail from it. I learnt about SMTP relays, so I configured Postfix on a Debian VM and it works flawlessly. Next part was to recieve mail on it and I learnt about Dovecot, Courier, Cyrus and lastly NGINX. I gave up on the first three as I simply could not paste the information together from the deocumentation and other sources to accomplish the service I wanted. I stuck around with NGINX because the official website actually had a dedicated entry to an IMAP proxy with an example, which I tried to follow.

My first issues arose when I tried to, as the guide said, build NGINX with the required options to support the IMAP proxy. Building ZLIB and PCRE went fine, OpenSSL wasnt as easy though as the "./Configure darwin64-x86_64-cc --prefix=/usr" command resulted in an error saying the commandline doesnt recognise "-Arch" after running "make". I tried it on Debian, Alpine, Ubuntu and now Arch and all of them threw this error. So in the end I just used "./config --prefix=/usr" and it compiled fine.

The next problem was with running "make" after configuring NGINX. The IMAP proxy guide says to use these parameters: "./configure --with-mail --with-mail_ssl_module --with-openssl=[DIR]/openssl-1.1.1". Now I figured that "[DIR]" is simply supposed to symbolise the directory where OpenSSL is installed, and when configuring OpenSSL the "--prefix=/usr" means that it will install under the "/usr" directory. So when I type in "--with-openssl=/usr/ssl" and run "make", it errors out saying it cannot find folders and files in that directory, even though OpenSSL is installed there, and running "openssl version" says version 1.1.1 is installed. So my next logical though was to tell it the directory is the one where I compiled and made OpenSSL from. After running make it seems to do something, just watching the lines makes it look like it is re-compiling OpenSSL, and after its done typing "nginx" as a command says it doesnt recognise it.

After this being the result in all the distros I tried I asked a question on Reddit and a user told me that I dont have to compile anything, as the default download (ie. sudo pacman -S nginx) for the distro usually has the mail module and everything for the proxy. Well I did so in Alpine and Ubuntu and after adding the "mail{}" block in the nginx.conf file the service wont start anymore as it doesnt recognise the "mail" module, I concluded that in fact it does not have the packages to handle them. Today I tried on Arch, I installed NGINX with pacman, added the "mail{}" block as a test and the service actually does start, although it only says the web server started.

With this I proceeded to follow the IMAP proxy guide and the archived guide for the PHP authentication script, but midway it hit me that Im not even sure if these configurations are for my purpose of "WM device -> Linux VM with NGINX -> imap.gmail.com" because all of them mention you having your mail server and backend servers. So here I am, writing this question.

First of all is it even possible to achieve what I want, in any way? Just like with Postfix where the device sends the mail to my VM and the VM sends it to the gmail servers, but here its IMAP. And if it is, can NGINX achieve this? I know my technical knowledge, especially in Linux is lackluster but I really thought I could solve this easly, but now its been a week since Im trying to set up an IMAP proxy. I would appreciate any help you can give me, and thank you so much for your time.

The guides I mentioned are:
NGINX IMAP proxy: https://docs.nginx.com/nginx/admin-guide/mail-proxy/mail-proxy/
Building NGINX: https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#sources
Authentication script: https://web.archive.org/web/20240117022353/https://www.nginx.com/resources/wiki/start/topics/examples/imapauthenticatewithapachephpscript/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 247
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready