ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Send an Email via SMTP from Command Line with cURL

    IT Discussion
    email smtp curl command line
    5
    16
    2.2k
    Loading More Posts
    • 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.
    • scottalanmillerS
      scottalanmiller
      last edited by

      cURL is more commonly installed than local SMTP clients, but supports the SMTP protocol, as well as others. It is therefore a really handy tool to use when you want to send out an email from a command line on any platform. So let's look at the configuration...

      First the command itself, showing gmail settings here by default but obviously fill in with your own details:

      curl --ssl-reqd
      --url 'smtps://smtp.gmail.com:465'
      --user '[email protected]:password'
      --mail-from '[email protected]'
      --mail-rcpt '[email protected]'
      --upload-file mail.txt

      You then need a properly formatted mail.txt file:

      From: "User Name" [email protected]
      To: "Recipient User" [email protected]
      Subject: Just a test

      This is the body of the email.

      1 ObsolesceO 2 Replies Last reply Reply Quote 4
      • 1
        1337 @scottalanmiller
        last edited by 1337

        @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

        First the command itself, showing gmail settings here by default but obviously fill in with your own details:

        Does it work? I thought gmail required OAuth nowadays and you couldn't use plain username & password for authentication anymore.

        DashrenderD scottalanmillerS 2 Replies Last reply Reply Quote 0
        • DashrenderD
          Dashrender @1337
          last edited by

          @Pete-S said in Send an Email via SMTP from Command Line with cURL:

          @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

          First the command itself, showing gmail settings here by default but obviously fill in with your own details:

          Does it work? I thought gmail required OAuth nowadays and you couldn't use plain username & password for authentication anymore.

          gmail still allows the creation of app passwords.

          1 1 Reply Last reply Reply Quote 0
          • 1
            1337 @Dashrender
            last edited by

            @Dashrender said in Send an Email via SMTP from Command Line with cURL:

            @Pete-S said in Send an Email via SMTP from Command Line with cURL:

            @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

            First the command itself, showing gmail settings here by default but obviously fill in with your own details:

            Does it work? I thought gmail required OAuth nowadays and you couldn't use plain username & password for authentication anymore.

            gmail still allows the creation of app passwords.

            OK, then it works for now I guess.

            I always cringe when I see MSPs that set up their clients MFPs and other devices using random gmail accounts.

            IMHO it's unprofessional and much better to use a real transactional email service for these kinds of applications.

            DashrenderD scottalanmillerS 2 Replies Last reply Reply Quote 1
            • DashrenderD
              Dashrender @1337
              last edited by

              @Pete-S said in Send an Email via SMTP from Command Line with cURL:

              IMHO it's unprofessional and much better to use a real transactional email service for these kinds of applications.

              such as?

              1 1 Reply Last reply Reply Quote 0
              • ObsolesceO
                Obsolesce @scottalanmiller
                last edited by Obsolesce

                @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                --user '[email protected]:password'

                Might not want to put username & password in a script if scripting this. At least put them as environment variables if nothing else. Also not a great option, but better than plain text in script.

                scottalanmillerS 1 Reply Last reply Reply Quote 0
                • 1
                  1337 @Dashrender
                  last edited by 1337

                  @Dashrender said in Send an Email via SMTP from Command Line with cURL:

                  @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                  IMHO it's unprofessional and much better to use a real transactional email service for these kinds of applications.

                  such as?

                  Common providers are postmark, sendgrid, mailgun etc. We use zoho's zeptomail. There is a bunch of them. Search for transactional email providers.

                  Transactional email is not used for marketing, so it's a different service and providers that offers both separate them.

                  Deliverability and speed is the important features for transactional mail.

                  Most providers offers both API and SMTP access so it's easy to set up.

                  scottalanmillerS 2 Replies Last reply Reply Quote 0
                  • scottalanmillerS
                    scottalanmiller @Obsolesce
                    last edited by

                    @Obsolesce said in Send an Email via SMTP from Command Line with cURL:

                    @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                    --user '[email protected]:password'

                    Might not want to put username & password in a script if scripting this. At least put them as environment variables if nothing else. Also not a great option, but better than plain text in script.

                    Often this wouldn't be scripted, it would just be a one time command. But good to note.

                    1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller @1337
                      last edited by

                      @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                      Common providers are postmark, sendgrid, mailgun etc. We use zoho's zeptomail.

                      We use MailGun with MangoLassi and ZeptoMail for NTG stuff and have done a lot of SendGrid for clients in the past. All three are good. ZeptoMail being my favourite thus far.

                      1 Reply Last reply Reply Quote 0
                      • scottalanmillerS
                        scottalanmiller @1337
                        last edited by

                        @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                        @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                        First the command itself, showing gmail settings here by default but obviously fill in with your own details:

                        Does it work? I thought gmail required OAuth nowadays and you couldn't use plain username & password for authentication anymore.

                        It works with some providers for sure, I've been using it. I don't actually use Gmail much so haven't actually tested that. Good point.

                        1 Reply Last reply Reply Quote 0
                        • scottalanmillerS
                          scottalanmiller @1337
                          last edited by

                          @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                          @Dashrender said in Send an Email via SMTP from Command Line with cURL:

                          @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                          @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                          First the command itself, showing gmail settings here by default but obviously fill in with your own details:

                          Does it work? I thought gmail required OAuth nowadays and you couldn't use plain username & password for authentication anymore.

                          gmail still allows the creation of app passwords.

                          OK, then it works for now I guess.

                          I always cringe when I see MSPs that set up their clients MFPs and other devices using random gmail accounts.

                          IMHO it's unprofessional and much better to use a real transactional email service for these kinds of applications.

                          It depends. If it is going out to customers, then it's weird. If it is for purely internal stuff then transactional email doesn't make too much sense. But if it is internal, normally you can just use whatever internal tool you already have.

                          1 1 Reply Last reply Reply Quote 0
                          • scottalanmillerS
                            scottalanmiller @1337
                            last edited by

                            @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                            Transactional email is not used for marketing, so it's a different service and providers that offers both separate them.
                            Deliverability and speed is the important features for transactional mail.
                            Most providers offers both API and SMTP access so it's easy to set up.

                            Yeah, API is best for SO many reasons.

                            Common perfect use cases...

                            Notifications from IoT devices (printers, monitoring devices)
                            Alerts from your monitoring software
                            Status updates from your ticketing system
                            "You have a new voicemail" notification from your phone system

                            1 Reply Last reply Reply Quote 0
                            • DashrenderD
                              Dashrender
                              last edited by

                              Looks like Google is doing everything they can do to kill application passwords.

                              I just checked another account that's never used one, and the option is no longer available.

                              1 Reply Last reply Reply Quote 0
                              • 1
                                1337 @scottalanmiller
                                last edited by 1337

                                @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                                @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                                @Dashrender said in Send an Email via SMTP from Command Line with cURL:

                                @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                                @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                                First the command itself, showing gmail settings here by default but obviously fill in with your own details:

                                Does it work? I thought gmail required OAuth nowadays and you couldn't use plain username & password for authentication anymore.

                                gmail still allows the creation of app passwords.

                                OK, then it works for now I guess.

                                I always cringe when I see MSPs that set up their clients MFPs and other devices using random gmail accounts.

                                IMHO it's unprofessional and much better to use a real transactional email service for these kinds of applications.

                                It depends. If it is going out to customers, then it's weird. If it is for purely internal stuff then transactional email doesn't make too much sense. But if it is internal, normally you can just use whatever internal tool you already have.

                                Typical scenario with gmail is that someone sets up a MFP to use a random gmail address for sending alerts and scanned documents.

                                When the user scans the document it's often sent to his own email address [email protected]. So primarily internal.

                                Well, problem is that gmail saves mail sent over SMTP in the sent folder. Which means that the "printer guy", who if often not even an employee, can read all the scanned document that was ever scanned and emailed by logging in to the gmail account he set up.

                                And of course sent email coming from outside your domains might be flagged as spam. So people scan documents and it doesn't work. I mean the list of problems is long.

                                Having printers and devices using internal email address of a domain you control, is not always the best option but I'm fine with that.

                                scottalanmillerS 1 Reply Last reply Reply Quote 0
                                • scottalanmillerS
                                  scottalanmiller @1337
                                  last edited by

                                  @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                                  @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                                  @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                                  @Dashrender said in Send an Email via SMTP from Command Line with cURL:

                                  @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                                  @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                                  First the command itself, showing gmail settings here by default but obviously fill in with your own details:

                                  Does it work? I thought gmail required OAuth nowadays and you couldn't use plain username & password for authentication anymore.

                                  gmail still allows the creation of app passwords.

                                  OK, then it works for now I guess.

                                  I always cringe when I see MSPs that set up their clients MFPs and other devices using random gmail accounts.

                                  IMHO it's unprofessional and much better to use a real transactional email service for these kinds of applications.

                                  It depends. If it is going out to customers, then it's weird. If it is for purely internal stuff then transactional email doesn't make too much sense. But if it is internal, normally you can just use whatever internal tool you already have.

                                  Typical scenario with gmail is that someone sets up a MFP to use a random gmail address for sending alerts and scanned documents.

                                  When the user scans the document it's often sent to his own email address [email protected]. So primarily internal.

                                  Well, problem is that gmail saves mail sent over SMTP in the sent folder. Which means that the "printer guy", who if often not even an employee, can read all the scanned document that was ever scanned and emailed by logging in to the gmail account he set up.

                                  And of course sent email coming from outside your domains might be flagged as spam. So people scan documents and it doesn't work. I mean the list of problems is long.

                                  Well when lots and lots of companies still demand to only use Gmail already, it's not so weird.

                                  You'd be amazing how often we get people requiring that they stay on Yahoo and AOL addresses for their businesses. I kid you not.

                                  travisdh1T 1 Reply Last reply Reply Quote 0
                                  • travisdh1T
                                    travisdh1 @scottalanmiller
                                    last edited by

                                    @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                                    @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                                    @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                                    @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                                    @Dashrender said in Send an Email via SMTP from Command Line with cURL:

                                    @Pete-S said in Send an Email via SMTP from Command Line with cURL:

                                    @scottalanmiller said in Send an Email via SMTP from Command Line with cURL:

                                    First the command itself, showing gmail settings here by default but obviously fill in with your own details:

                                    Does it work? I thought gmail required OAuth nowadays and you couldn't use plain username & password for authentication anymore.

                                    gmail still allows the creation of app passwords.

                                    OK, then it works for now I guess.

                                    I always cringe when I see MSPs that set up their clients MFPs and other devices using random gmail accounts.

                                    IMHO it's unprofessional and much better to use a real transactional email service for these kinds of applications.

                                    It depends. If it is going out to customers, then it's weird. If it is for purely internal stuff then transactional email doesn't make too much sense. But if it is internal, normally you can just use whatever internal tool you already have.

                                    Typical scenario with gmail is that someone sets up a MFP to use a random gmail address for sending alerts and scanned documents.

                                    When the user scans the document it's often sent to his own email address [email protected]. So primarily internal.

                                    Well, problem is that gmail saves mail sent over SMTP in the sent folder. Which means that the "printer guy", who if often not even an employee, can read all the scanned document that was ever scanned and emailed by logging in to the gmail account he set up.

                                    And of course sent email coming from outside your domains might be flagged as spam. So people scan documents and it doesn't work. I mean the list of problems is long.

                                    Well when lots and lots of companies still demand to only use Gmail already, it's not so weird.

                                    You'd be amazing how often we get people requiring that they stay on Yahoo and AOL addresses for their businesses. I kid you not.

                                    5f34099e-464c-4cd3-a7e3-f7845ca46d05-picardfacepalm.jpg

                                    1 Reply Last reply Reply Quote 2
                                    • 1 / 1
                                    • First post
                                      Last post