Send an Email via SMTP from Command Line with cURL
-
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.txtYou then need a properly formatted mail.txt file:
From: "User Name" [email protected]
To: "Recipient User" [email protected]
Subject: Just a testThis is the body of the email.
-
@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.
-
@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.
-
@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.
-
@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?
-
@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.
-
@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.
-
@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.
-
@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.
-
@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.
-
@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.
-
@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 -
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.
-
@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.
-
@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.
-
@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.