Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Support
  3. I want to have a script send an email via Cloudron

I want to have a script send an email via Cloudron

Scheduled Pinned Locked Moved Solved Support
4 Posts 3 Posters 598 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8 Offline
    8 Offline
    81ewlska
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    1
    • nebulonN Offline
      nebulonN Offline
      nebulon
      Staff
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • nebulonN nebulon marked this topic as a question on
      • 8 Offline
        8 Offline
        81ewlska
        wrote on last edited by
        #3

        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.

        girishG 1 Reply Last reply
        1
        • 8 81ewlska

          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.

          girishG Offline
          girishG Offline
          girish
          Staff
          wrote on last edited by girish
          #4

          @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 from docker 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.

          1 Reply Last reply
          1
          • girishG girish has marked this topic as solved on
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Bookmarks
          • Search