Advice on sending email from command line via Gmail...

I'd like to send one-line emails from the command line[1], via my Gmail account. I have searched here and on line but most of the search results are from before Google changed the interface to Gmail around 2022. Does anyone have any advice? Thanks.


[1] or at least from the text mode application I use at work, written in dBase language but compiled with Harbour Compiler.
uname -a =
FreeBSD pr5.blank.blank 13.2-RELEASE-p10 FreeBSD 13.2-RELEASE-p10 GENERIC amd64
 
afaik mutt() can handle imap and smtp, maybe that helps. (it even provides some batch processing functionality, so maybe that can be used to send mails directly fromm the command line)
 
Is your e-mail sending and receiving set up? With an MTA (like sendmail or DMA) and an IMAP/POP receive program (like fetchmail)?

If yes, all it takes to send an e-mail is the mail command, which can be run from the CLI, for example such:
echo "Hallo world this is Exeter" | mail -s "Hi there" foobar@example.com

The mail program is an MUA or "mail user agent"; the program that you type messages to be sent into, or use to look at messages you have received. There are also many other CLI-based e-mail programs or MUAs, including mutt, alpine, and elm; the advantage of mail is that it is part of the FreeBSD base, and always there; it also exists on most other Unixes (such as Linux). All these MUAs can talk to the MTA or "mail transfer agent" to send mail, and they use copies of the messages stored on your computer by a receive program. The bigger and more complex MUAs can usually also talk directly to an IMAP server, which is probably easier and safer than configuring fetchmail. But for sending e-mail, the simplicity of mail is hard to beat.
 
You may need to do a bit of setup I think Gmail recently did stuff to make it harder to use "third party" applications. I ran across this with Claws-mail
 
ssmtp and msmtp both frequently show up in searches, however ssmtp is unmaintained. Anybody tried them?
 
I use msmtp. Gmail did make changes making it more difficult to use with 3rd party apps, supposedly for our safety, more likely part of google's attempt to close out anyone else. I give instructions on my mutt page https://srobb.net/mutt.html#getmail

It's about halfway down, you can search the page for May 30th, it's just under that. That part talks about setting the app password for getting mail, but you can use the same password for sending with msmtp. (I go into setting up msmtp under the sending mail section).
Ah I see I made a separate page for it to make it easier to find.

 
In my case, I didn't need oauth. I don't know if it's changed, but when I did it, I just had to set a special app password. It may have changed, Google gets more and more..proprietary seems the best word.
 
Back
Top