I want to have a script send an email via Cloudron
-
Heyo,
I have a script I'm going to run on my Cloudron server, it updates a .ics file hosted with Surfer. I'd like to receive an email at my regular (non-Cloudron) account when the login credentials stop working or for some other reason the script updating the .ics file fails.
Is there a way I can send emails from the script while leaving Cloudron email in its stock state? The automated emails it sends right now work just fine. I'd prefer not to have to enable receiving, set up user accounts, etc. This thread is tangentially related but didn't hit the nail on the head: https://forum.cloudron.io/topic/3965/use-cloudron-email-for-sending-email-smtp-on-application-hosted-outside-cloudron
Thanks for your help
-
not sure I understand what you ask for. How is email sending, surfer and the .ics file connected? If you just want to send an email via a mail account on your Cloudron, I guess you can use any email client which supports scripting to do so?
Where would this script, you refer to, run?
-
-
The script currently lives in the home directory of the VPS instance that hosts Cloudron, and it updates a file exposed to the world by Surfer. Ideally there is a line or two I can add to the script (python) that sends an email if the script fails. Obviously Cloudron has some built-in capabilities for this, since it sends emails; can I access these capabilities easily? I'd like to avoid having to install an email client, set up users, etc.
-
@81ewlska you can send a mail like this:
- Get mail server container IP -
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mail
- Get relay auth token -
docker inspect -f '{{range $index, $value := .Config.Env}}{{if eq (index (split $value "=") 0) "CLOUDRON_RELAY_TOKEN" }}{{range $i, $part := (split $value "=")}}{{if gt $i 1}}{{print "="}}{{end}}{{if gt $i 0}}{{print $part}}{{end}}{{end}}{{end}}{{end}}' mail
. Don't ask me how this works, I stole it from Stack overflow But essentially, CLOUDRON_RELAY_TOKEN is an environment variable in the container. You can also get this fromdocker inspect mail | grep CLOUDRON_RELAY_TOKEN
and do some string manipulation.
Then, send mail (
example.com
below is your primary domain):swaks --server <mail_server_ip> --port 2525 --from no-reply@example.com --to test@cloudron.io \ --body "Test mail from Cloudron" \ --auth-user no-reply@example.com --auth-password <relay_token>
Note: above only works from the server itself. You cannot send mails from outside the server using a token.
- Get mail server container IP -
-