6

I am trying to use the mailx program to send an e-mail.

I want the name of the person to be included in the [email protected] like the normal one on Microsoft Outlook or gmail account e.g "Thomas<[email protected]>"

ls -l $HOME | mailx -r "[email protected]" -s "The content of my home directory"    [email protected]
Anthon
  • 78,313
  • 42
  • 165
  • 222
Mree
  • 61
  • 2

1 Answers1

3

You can get the "Thomas<[email protected]>" when you use sendmail directly. That is not so complicated, you just need to create the header

From: [email protected]
To: Thomas <[email protected]>
Subject: The content of my home directory

<output from ls>

There has to be an empty line between the header and the content. You can achieve this with:

(echo -e 'From: [email protected]\nTo: Thomas <[email protected]>Subject: The content of my home directory\n\n' ls -l $HOME | sendmail -t

However, please note, that e.g. in Thunderbird, if the recipient has a name for [email protected] in the addressbook, then that name will be displayed, instead of Thomas

Anthon
  • 78,313
  • 42
  • 165
  • 222
  • 1
    for UNIX-HP mailx does not have the -t option like the sendmail utility. the -r for UNIX is for the from address – Mree Jul 18 '14 at 08:16
  • 1
    @Mree Then just try with the double quoted text: `-r "Thomas "` – Anthon Jul 18 '14 at 08:34
  • 1
    I have tried it, it only comes with e-mail address only – Mree Jul 18 '14 at 09:37
  • 2
    @mree Ok, but that is the case on Linux as well. If you want the recipient to see the name you put there, it has to be in the mail header and then you cannot use mailx. I will update my answer for an alternative. – Anthon Jul 18 '14 at 12:13