It's pretty simple but may save you a couple of minutes reading the docs:
echo -e "Subject:Test \n\nTest Msg" | sendmail -t "[email protected],[email protected]"
-e enables escape sequences on the
sendmail to read the header for
echo 'Test Msg' | mail -s 'Test' [email protected],[email protected]
-s sets subject
The examples above will rely on having Linux machines properly setup. To send mails from Java, you'll be better served using SimpleJavaMail's API, which makes it a breeze to connect and send emails using a proper SMTP server.
Email email = EmailBuilder.startingBlank() .from("Frankie", "[email protected]") .to("Someone Else", "[email protected]") .withSubject("Now this is proper!") .withPlainText("SMTP servers make the world go round!") .buildEmail();
You can call bash from Java if, say, you'll want a fallback for when your SMTP server doesn't respond.
As an Amazon Associate I may earn from qualifying purchases on some links.
If you found this page helpful, please share.