How to change the sender's name or e-mail address in mutt?

泪湿孤枕 提交于 2019-11-29 21:12:33

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.

luanjunyi

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!

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!

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>\""

for a one time change you can do this:

export EMAIL='sender@somewhere.com'; mutt -s "Elvis is dead" receiver@somewherelse.com

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!