80

How can I change the sender's name or e-mail address (From: header) used by mutt?

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
user1630087
  • 811
  • 1
  • 7
  • 5
  • 1
    Do you want to change it once, in a configuration file, or you want to change it while composing an e-mail? By the way, this is probably better asked on SuperUser. – ArjunShankar Aug 28 '12 at 11:35
  • echo "File $Filename not present" | mutt -s '$MailSubject' -c "abc@yahoo.com"."xyz.yahoo.com" – user1630087 Aug 28 '12 at 11:42

7 Answers7

79

Normally, mutt sets the From: header based on the from configuration variable you set in ~/.muttrc:

set from="Fubar <foo@bar>"

If this is not set, mutt uses the EMAIL environment variable by default. In which case, you can get away with calling mutt like this on the command line (as opposed to how you showed it in your comment):

EMAIL="foo@bar" mutt -s '$MailSubject' -c "abc@def"

However, if you want to be able to edit the From: header while composing, you need to configure mutt to allow you to edit headers first. This involves adding the following line in your ~/.muttrc:

set edit_headers=yes

After that, next time you open up mutt and are composing an E-mail, your chosen text editor will pop up containing the headers as well, so you can edit them. This includes the From: header.

ArjunShankar
  • 23,020
  • 5
  • 61
  • 83
  • I'm new to shell scripting.. Can you explain how to change the configuration file?? and where it is available??? – user1630087 Aug 28 '12 at 12:05
  • 2
    The file ***is*** `~/.muttrc` (i.e. `/home/$USERNAME/.muttrc`). You edit it with a text editor. If its not there, you create it. I wouldn't call it shell scripting, its just opening an editor, and writing a line in a file ;) – ArjunShankar Aug 28 '12 at 12:39
  • 6
    I'd like to add that even without `set edit_headers=yes` you can press the `edit-from` shortcut (default: ESC f) to edit the from field. – Andrew Savinykh May 16 '13 at 01:57
  • 3
    Mutt also allows specifying an alternate muttrc file to use. Therefore for a one-shot change to the from address, create a new file: `echo set from="Fubar " > temprc` and then use it: `mutt -s "my subject" -F testrc recipient@example.com` – Ben Nov 06 '13 at 16:36
  • @AndrewSavinykh the link is dead :( – 3kstc Feb 21 '19 at 03:26
  • @3kstc seems like it is. Feel free to fix it! – Andrew Savinykh Feb 21 '19 at 03:38
  • 1
    Setting `set use_envelope_from = yes` in .muttrc finally worked for me. This adds the -f option when calling sendmail to deliver the mail, forcing it to use the same address for the envelope as for the From: header field. – elim Mar 13 '19 at 11:33
35

If you just want to change it once, you can specify the 'from' header in command line, eg:

mutt -e 'my_hdr From:obama@whitehouse.org'

my_hdr is mutt's command of providing custom header value.

One last word, don't be evil!

fthiella
  • 48,073
  • 15
  • 90
  • 106
luanjunyi
  • 1,634
  • 1
  • 15
  • 17
  • 4
    It works thanks. e.g: `echo "I love you body" | mutt -a "/tmp/file.zip" -s "ZIP" -c friend1@email.com -e 'my_hdr From:sender@company.com' -- main@email.com` –  Jun 26 '13 at 10:33
  • Note the default domain (user@domain.com) will be the system's `hostname`. [Changing the `hostname` on aws is easy](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-hostname.html), I think on other systems, it should be similar. – bobobobo Jan 16 '14 at 01:01
28

before you send the email you can press <ESC> f (Escape followed by f) to change the From: Address.

Constraint: This only works if you use mutt in curses mode and do not wan't to script it or if you want to change the address permanent. Then the other solutions are way better!

reox
  • 5,036
  • 11
  • 53
  • 98
  • I wrote a response before realizing the `from` was wrong (I almost never use mutt). Saved my bacon, thanks! – Cameron Sep 14 '16 at 20:07
12

One special case for this is if you have used a construction like the following in your ~/.muttrc:

# Reset From email to default
send-hook . "my_hdr From: Real Name <email@example.com>"

This send-hook will override either of these:

mutt -e "set from=email@example.com"
mutt -e "my_hdr From: Other Name <otheremail@example.com>"

Your emails will still go out with the header:

From: Real Name <email@example.com>

In this case, the only command line solution I've found is actually overriding the send-hook itself:

mutt -e "send-hook . \"my_hdr From: Other Name <otheremail@example.com>\""
puzzlement
  • 548
  • 5
  • 10
6

For a one time change you can do this:

export EMAIL='sender@example.com'; mutt -s "Elvis is dead" receiver@bar.com
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
geezer
  • 81
  • 1
  • 2
  • Thanks. I put export EMAIL='sender@somewhere.com' in .bashrc and now it's permanent. – Andrew Sep 23 '14 at 14:42
  • @Andrew How did you put it there? Did you just `nano` the file and append that one liner at the bottom of the file - or did you put other code around it? – 3kstc Feb 21 '19 at 04:17
  • @3kstc just put the export statement as I wrote it in you .bashrc - but be sure .bashrc is being sourced or else the variable EMAIL will not be set. This may be the case when invoking mutt using cron or ssh or other shells (that are not bash) as all of the possible user profile related files may not be executed depending on how the shell is started – Andrew Sep 08 '19 at 16:08
  • Note that `EMAIL='sender@example.com' mutt ...` is sufficient (no `export`, no `;`). There is no need to export the `EMAIL` environment variable permanently. The syntax I show sets the environment variable for a single program invocation. – Christopher Schultz Nov 04 '22 at 16:34
2

Step 1: Locate Muttrc which in case of Oracle Linux 7.6 could be found in /etc Step 2: Open the file in vi editor to add the below entries viz. vi /etc/Muttrc Step 3: Contents to be added or/and uncommented

set from = "user@domain.com" set realname = "Realname of the user"

Step4: Save the file and exit. Also attempt sending an email with the syntax that follows,

echo "$Body of the email" | mutt -a "$name_of_the_attachment" -s $subject_line_of_the_email" -- $USER@DOMAIN.com

1

100% Working!

To send HTML contents in the body of the mail on the go with Sender and Recipient mail address in single line, you may try the below,

export EMAIL="sender@example.com" && mutt -e "my_hdr Content-Type: text/html" -s "Test Mail" "recipient@example.com" < body_html.html

File: body_html.html

<HTML>
<HEAD> Test Mail </HEAD>
<BODY>
<p>This is a <strong><span style="color: #ff0000;">test mail!</span></strong></p>
</BODY>
</HTML>

Note: Tested in RHEL, CentOS, Ubuntu.

M.S. Arun
  • 1,053
  • 13
  • 22
  • 1
    There is no error. It just doesn't work. The correct solution is to use `set from=email@example.com` in `~/.muttrc` – FractalSpace Apr 18 '19 at 13:50