I can use
echo "My Mail content" | exim [email protected]
to send an email, but it does not contain a subject for the message
How can I send an email with subject, “From” and “Reply-To” Headers from the command-line in exim?
exim -i -t <<< 'From: My Self <[email protected]> To: Recip One <[email protected]>, Recip Two <[email protected]> Subject: Test message content line 1 content line 2'
This works for any sendmail-compatible MTA not just exim. If you have sendmail you could run same command but start with "sendmail -i -t...".
Of course you could load the input from a text file instead.
exim -i -t < file/path.txt
Quotes are not needed for label part of email addresses before angle backets.
-i switch prevents dot-line-termination. If you just run "exim -t" and paste or type in the content interactively then skip the -i switch and you can end with line containing just dot then a blank line (don't know why the extra blank line is needed--it didn't used to be).
-t derives recipients from the content you give rather than specifying as command-line parameter. Email agents expect To: field to be set and honor labels, so you should normally send it. If you do send a To: then use -t switch because specifying recipients on command line would be redundant and a source of possible conflict in that case.
Another tactic is to use s-nail's mailx program. With s-nail installed, just add "set mta=/usr/bin/exim" (or /usr/sbin/exim or wherever it resides) to /etc/mail.rc or your personal ~/.mailrc and use mailx like so:
mailx -s 'subject line' 'Recip One <[email protected]>' 'Recip Two <[email protected]>' <<< 'content line 1 content line 2'
mailx -s 'subject line' 'Recip One <firstname.lastname@example.org>' 'Recip Two <[email protected]>' < file/path.txt
Mailx has a nice -a switch for adding file attachments. If you're running a very old version of s-nail, there is no 'mta' setting and you need to replace /usr/sbin/sendmail or /usr/bin/sendmail (or similar) with a sym link to your exim binary.
Answered by user306125 on January 1, 2022
Exim expects to receive a full RFC 5322 / 2822 / 822 email message as input. So you need to give the headers in the form of... headers.
$ (echo "To: foo@bar"; echo "Reply-To: [email protected]" echo "Subject: Hello!"; echo ""; echo "My Mail Content") | sendmail foo@bar
$ sendmail foo@bar <<'EOF' From: "The Great Quux" <baz@quux> To: "Fred Foobar" <foo@bar> Reply-To: dev@null Subject: Hello! Content-Type: text/plain; charset=utf-8 My Mail Content EOF
(Not sure if the names in From/To have to be quoted. RFC 5322 seems to say that they should)
Answered by user1686 on January 1, 2022
2 Asked on September 2, 2020 by hack-r
1 Asked on September 1, 2020 by neuser
1 Asked on September 1, 2020 by user2534761
1 Asked on August 29, 2020 by prateek
6 Asked on August 24, 2020 by pietro
1 Asked on August 21, 2020 by vlada
2 Asked on August 20, 2020 by fadi
0 Asked on August 17, 2020 by mirza
1 Asked on August 15, 2020 by arvendra-dubey
3 Asked on August 15, 2020 by prometheus
1 Asked on August 8, 2020 by arjun
1 Asked on August 7, 2020 by adam-przedniczek
Get help from others!