It's pretty simple but may save you a couple of minutes reading the docs:

Sendmail:

echo -e "Subject:Test \n\nTest Msg" | sendmail -t "[email protected],[email protected]"

-e enables escape sequences on the echo.

-t instructs sendmail to read the header for To:, Cc:, Bcc: and Subject: lines.

Mail:

echo 'Test Msg' | mail -s 'Test' [email protected],[email protected]

-s sets subject

Java:

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 may want to see on how to call bash (sendmail) from Java if, say, you'll want a fallback for when your SMTP server doesn't respond.