0

For a username "A&B"

[abuser@myserver] chfn -f "A&B"
Changing finger information for abuser
Password:
Finger information changed.
[abuser@myserver] mail -s Test [email protected]
Hello World!
Cc:
[abuser@myserver]

When this mail arrives, "&" appears to be replaced by the username in the From field in the email.

From: AAbuserB [abuser@myserver]

3 Answers 3

0

Try with

mail -a "From: A&B <abuser@myserver>" -s Test [email protected]
3
  • Thanks for the reply, but I get "mail: invalid option -- a". Furthermore, this is for an automated system email that doesn't hard-code the from address. Sep 9, 2011 at 8:45
  • You seem to have a very old mail command or different implementation of it than I, then. Have you tried to escape & character: chfn -f "A\&B"? Sep 9, 2011 at 9:40
  • Yep - escaping doesn't work. Sep 9, 2011 at 11:50
0

Try with Quoted Printable Encoding:

chfn -f "=?ISO-8859-15?Q?A=26B?="

where =26 is the ampersand. Looks ugly, but should do the trick.

Edit: It is not mail, but you should then try other alternatives: Use sendmail (the interface of your MTA and not sendmail itself). Or mutt is also good for scripted sending of mails. The mail command is too restricted in functionality in this case. And if you really need a mail command then you need to write a wrapper called mail that internally calls mutt for sending.

3
  • Apologies for slow reply. Doesn't seem to work... chfn -f "=?ISO-8859-15?Q?A=26B?="... chfn: full name: '=' is not allowed. Sep 30, 2011 at 9:13
  • @NickPierpoint Then write a bug report for mail or use other alternatives as described in my edit.
    – mailq
    Sep 30, 2011 at 12:02
  • I get the same behaviour using mutt - I presume the issue is with the mta (sendmail in this case). Sep 30, 2011 at 12:58
0

This behaviour is caused by the Mail Transport Agent (MTA) handling of & characters in the mailbox name in /etc/passwd

From the passwd man page:

gcos-field is the user's real name, along with information to pass along in a mail- message heading. (It is called the gcos-field for historical reasons.) An ``&'' (ampersand) in this field stands for the login name (in cases where the login name appears in a user's real name).

The workaround in this case is to explicitly set the From address in the mail client.

For example, using mutt (as suggested by @mailq):

~/.muttrc

set realname="A&B"
set from="ab@myserver"
set use_from=yes

Sending a test email...

echo "Test body" | mutt -s "Test" [email protected]

Seems to work fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .