I need to send email using postfix as server once wifi has received IP address (based on dhcpcd). It seems that
systemd by default boot postfix before wifi (wlan0) is ready. The consequence associated with this is that postfix failed to run in background and email can not be sent, successfully. However, if I run the following script (namely abc.sh) on boot, email can definitely get through:
sleep 60 systemctl restart postfix echo 'email content' | mail -s 'titile' firstname.lastname@example.org
The service file associated with abc.sh is given below:
[Unit] Description=pptp_setup Requires=network-online.target After=network-online.target [Service] Type=forking ExecStart=/home/pi/script/abc.sh [Install] WantedBy=multi-user.target
Note that sleep 60 and systemctl restart postfix is the trick to ensure the email is sent. if only sleep 60 is applied without restarting postfix, the email still can not send through as postfix is not booted properly initially ( as mentioned above, it may get loaded before receiving an IP). Also If only postfix is restarted without sleep for 60 seconds, the postfix reboot still would still fail, even Requires=network-online.target and After=network-online.target have been applied in the service file.
My question is how to set postfix correctly so that it gets booted after wifi has received ip address.