Sendmail (or Mail) with subject on a single line
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 "a@example.com,b@example.com"
-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' a@example.com,b@example.com
-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", "frankie@example.com")
.to("Someone Else", "someone.else@example.com")
.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.