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 toaddress@domain.com like the normal one on Microsoft Outlook or gmail account e.g "Thomas<tmuller@gmail.com>"

ls -l $HOME | mailx -r "fromaddress@domain.com" -s "The content of my home directory"    toaddress@domain.com
Anthon
  • 79,293
Mree
  • 61

1 Answers1

3

You can get the "Thomas<tmuller@gmail.com>" when you use sendmail directly. That is not so complicated, you just need to create the header

From: fromaddress@domain.com
To: Thomas <tmuller@gmail.com>
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: fromaddress@domain.com\nTo: Thomas <tmuller@gmail.com>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 tmuller@gmail.com in the addressbook, then that name will be displayed, instead of Thomas

Anthon
  • 79,293
  • 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 <tmuller@gmail.com>" – 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