AnswerBun.com

Exim: How to send email (with headers) from command line?

Super User Asked by Robby75 on January 1, 2022

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?

2 Answers

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'

or

mailx -s 'subject line' 'Recip One <[email protected]>' '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: [email protected]";
   echo "Reply-To: [email protected]"
   echo "Subject: Hello!";
   echo "";
   echo "My Mail Content") | sendmail [email protected]
$ sendmail [email protected] <<'EOF'
From: "The Great Quux" <[email protected]>
To: "Fred Foobar" <[email protected]>
Reply-To: [email protected]
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

Add your own answers!

Related Questions

Download a file via HTTP from a script in Windows

8  Asked on February 24, 2021 by jason-r-coombs

       

ZSH prints the command I ran before showing the output

1  Asked on February 24, 2021 by anish-sharma

         

Virtualization is locked in BIOS

1  Asked on February 23, 2021 by ben-r

     

Send email from gmail alias with ssmtp or other

0  Asked on February 23, 2021 by cclloyd

       

Unable to set or remove a login PIN on Windows 10

2  Asked on February 22, 2021 by scott-severance

     

Open PDFs in Adobe instead of in Google Chrome

5  Asked on February 22, 2021 by ramzi-kahil

   

command not found after switching users

0  Asked on February 22, 2021 by dor00012

     

PC starts, but no display from the monitor

1  Asked on February 20, 2021 by micjaakson

     

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir