Linux – How to override smtp host details while using sendmail

linuxsendmail

I have a requirement to send the output of certain output as an email to myself.
like df -h , free -m etc.
I have used mailx command with override of smtp host with command mailx -S smtp="smtphost.com" , I was able to receive the mail but the formatting was not correct and it came as a text/plain content type. It is not aligned and it is getting difficult to read the content.

In all the forums/blogs, I saw that we will be able to send the html content inside mail using sendmail. But I wanted to try out by overriding the smtp host. But unable to do the same. Any help would be much appreciated.

I am thinking that there has to be a way in mailx command which allows the mail to be send with html format or atleast the tab spaced output as seen in the linux. if this doesn't work by anyways then I need to get the sendmail working.

Best Answer

Look into the -a switch with mailx. You can add the formatted file as an attachment:

echo '<html><b>This is and HTML message</b></html>' > /tmp/abc.htm
echo "test from $USERNAME attached" | mailx -s "Test message" -a /tmp/abc.htm user@your.dom

If you want formatted output (ls -l for example) pipe the output to abc.txt and attach the same way.