Postfix as relay for Gmail from Arduino

Hello everyone,

I'm working since one month on a wired home security system project based on Arduino and Network (routers only, no computers).

As I learned a bit late that my Mega2560 could not work with SSL, and of course that email providers do not allow anymore SMTP connections on port 25, I've been disappointed on the first shot while I was reaching the end of my project, until I've heard about Postfix.

This part of my project is essential as it is made to receive email alerts when the Arduino makes detection.

As I use a Gli-net AR750S built on Openwrt in my project, essentially as a VPN gateway, it can also for sure provide sending emails implementing SSL to satisfy Gmail by forwarding an email sent from my LAN Arduino on SMTP 25 port to 587 port.

So I've been installing and configuring the plugin and that is what is does...quite...

I've been following a tuto (I will put the link at the end) from someone that had a similar idea...but I cannot reach the end.

For now I can connect from my PC with putty to my router and using sendmail I can receive email from my Gmail address 1 (sender) to my Gmail address 2 (recipient) and I receive perfectly the email with the certificate on address 2, and I can see in my sender mailbox the email sent also.

So, that it seems that on Wan side things are set up correctly.

Then I'm blocked with what seems to be a simple forward to my ISP box here...

I've checked everywhere on the net with the main.cf and master.cf different explanation and configuration. Thought it was firewall blocking and add some iptables rules. Thought it was maybe root access not allowed from my Arduino. Changed postfix transport file to nexthop...

Really, I'm turning around since two days. I have always the same result with the ino file from the tuto showing that gateway is reachable on port 25, but the email is not sent. Postfix seems to end the connection. I got this issue but I do not just know where to look !!!

I will appreciate your kind help here as I've been working really hard on my own on this project since a lot of time.

I will for sure give you all the information you need step by step.

For now, here is the link of the tuto followed. Actually I had to change little things to make it work.

I've changed also this:

</>
bool checkResponseCode(EthernetClient ethclient) {
/

* Check if connection to mta is still active
*/
char responseCode;
if (!(*ethclient).available()) {
// terminate connection and return error
(*ethclient).stop();
Serial.println(F("FAILED"));
return false;
}
else if ((*ethclient).available()) {
// check response code from mta
responseCode = (*ethclient).peek(); // just read first byte
if (responseCode >= '4') {
(*ethclient).println(F("QUIT)"));
Serial.println(F("FAILED"));
return false;
}
else {
return true;
}
}
}
</>

By putting in first Serial.println "Failed - unavailable" and in the second "Failed - Code >=4".

The serial monitor returns the first Failed (unavailable) after saying MTA OK, showing the MTA connection is OK but not the MTA communication...

Thank you for your help again.

Best regards.

Actually, I will add an important point:

My ISP box is configured in 192.168.1.1 (Main gateway) and my Gl-inet where Postfix resides in on 10.x.x.x acting as an Openvpn gateway where all the traffic goes through.

My LAN is behind on another router and was on 192.168.0.0/24.

Then I've tried to plug directly the Arduino to my Gli-net, but it is the same.

That is why I've tried Next hop in the transport config file...

Maybe it is where it messes up ! Different networks.

As you can see in the screenshot, I had put my code between marks but it does not seem to take it ...done from my cellphone.
Did I do something wrong?

Waiting for an answer I'm adding that I could not test my 25 port as telnet is not present in my Openwrt release.

I've seen on your site that I could use Dropbear instead but I have no idea about how to use it.

Any help on this, please?

Test from where?

Port is always there, question is of something is listening, netstat will show this.

sending unencrypted emails works just fine (at least to gmail), you do however need a TXT record with a SPF entry for the sending FQDN.

I this this setup just a couple of weeks ago, on Postfix, since my ISPs relay wasn't reliable, and was dropping 2 out of 3 emails, on a daily basis.

Hello,

I was saying this regarding the procedure I gave with the http link.
The user that did the tutorial is sending an email via telnet connecting from a client.

Actually my Arduino will act as a client connecting to my router on port 25.

This is to try before (as it is said) the Arduino sketch.
As you see the Arduino cannot send any mail and I have no information about what is happening here.

The netstat -an command gives the status about the listening port for 25 with IP 0.0.0.0 if I put inet_interfaces=all in the main.cf and IP 127.0.0.0 if I put only my router address.

If you have any idea about what is happening, and what should be the right config, thank you for helping.

??? Where do you see anonymous in my words?

sorry read anymore as anonymous ... my bad.

should be able to use netcat/ncat (nc) as telnet replacement.

Under Windows I do not think so...I've been developing my Arduino project under Windows.
Maybe I can put a Linux emulator...(I did this many years ago on my PC)...

in windows, use putty, some versions (of Win) still have telnet too.

1 Like

Actually I'm looking at this right now:
https://service.futurequest.net/index.php?/Knowledgebase/Article/View/36

When I use only the "Telnet" session with putty, putty just close off...I do not know why.

So I will try the link I gave. Do you think it might help?

You need to provide som additional information about your network.

Telnet to postfix on port 25 shouldn't immediately close the connection, you should be able to talk the SMTP protocol through the session.

HELO
MAIL FROM:
RCPT TO:
DATA

etc...

Does this work from the postfix host?

Telnet does not work as there is no telnet server on my router.
I asked if you've seen in one of my last post about Dropbear. How to enable it?
It seems telnet is not responding at all (because inactive).
It is useless here to ask a telnet client to connect to my router in that condition...

It is after having read this:

You don't need a telnet server, you need a telnet client as @frollic said:

image

You should see

220 $myhostname ESMTP ...

Then make your tests.

1 Like

Hi,

This does not work, putty closes doing this....and of course telnet is a client/server relation...it is not magic...
I've tried from a windows client it does the same : no answer at all.

But I will try the putty tunnel with the email sent through the SSH tunnel.

It is different than what I've been doing with putty connecting to the router and using sendmail: in this case it is the router itself that sends the email. It is not a push to the router.

So, the link I gave is not helping me.
And about Dropbear it seems actually to be the service building SSH tunnel on port 22...the one I'm using usually to connect with putty.

What I need is to push an email from a client to the router on port 25...any idea except telnet (that, once again is not running (Daemon should be telnetd) on my router)?

So....As I do the questions and answers I will proceed.
First of all, I've read that Postfix checks DNS before sending an email, then I've changed my DHCP settings of my Gli-net router to static and set up DNS.

I've tried with power shell on windows to send an email (discovered this while looking how to send an email from Windows).

After many failures I did it !!!

Simply changing the "my_networks" in main.cf by the single IP of my PC ! And it did the job.

About this I've seen on the net that sometimes they fill the IPs separated with commas, and sometimes not. Maybe it depends on the version of Postfix...

Now I will try with the Arduino sketch putting the Arduino IP....fingers crossed !

IT IS WORKIIIING !!!!
I'm so glad !
Anyway, I had to change eth0client in the code by client and restore the 9600 bauds...
Actually it works with 115200 (all my sketch is made with this serial speed) but it says "unavailable" as usual and in this mode there is kind of lack in the reception (many minutes before the email arrives).
I will maybe ask on an Arduino forum about this.
If you wish to answer anyway and know what's happening, please do not hesitate.

Before closing this post, I still need an answer about Postfix bitrate capacity.

Even if it works, it seems that there is a kind of random behaviour that I do not like here.

Sometimes the sketch says that postfix is unavailable while it has sent the email successfully...but with a strange delay.

It seems that when I put the Arduino serial baudrate at 115200 emails are queued or make a collision and re-uploading the sketch at 9600 then frees up the flow and all the emails that did not arrived arrive at once.

It seems to be more on Postfix side than on Arduino side. Postfix seems to react slowly then respect to Arduino's high rate.

I have to know exactly what is happening here. Rate has to be on phase between Arduino and Postfix.

Any help on this, please?