My server is CEntOS 7, and has sendmail but not mailx etc. Rather than install a new program I tested using sendmail directly, and found that this works:
echo -e "From: you@whatever\nTo: [email protected]\nSubject: this is the subject\n\nThis is the body,\nwith multiple lines." | sendmail -t For me this seems to be the simplest way to send a short email, as it does not require running or configuring a server or daemon, and can be done in a single command line.
The idea is that a message will simply alert me that a certain program threw an error, without revealing any potentially confidential info, and then I'll SSH to the server to inspect its logs. This way there's no need to bother with complications like attaching files or encrypting the transport.
Notes:
-etells echo to interpret '\n' and other escapes.-ttells sendmail to get recipient addresses from 'To:' in the message header.- If the mail does not arrive, use
tail /var/log/maillogto see error messages. - If sending to your gmail address, make a filter at gmail to keep them out of the junk folder.
- This sendmail is actually 'sendmail.postfix' (which might be normal); there's a man page here
The idea is that a message will simply alert me that a certain program threw an error, and then I'll SSH to the server to inspect its logs, so there's no need to bother with complications like attaching a file or encrypting the transport.