I've been trying to work through sending a html email from mailx on a linux server.
Few Notes:
- I have to specify a smtp server so therefore I cannot use sendmail (This is not something I can change on my end)
- I cannot install 3rd party things such as mutt. I will have to use mail or mailx
- Since my mail/x version is heirloom I do not have the --append or -a (attach header options)
- not sure if this helps at all but my linux distro is 7.3 (Maipo)
What I've seen in most posts on stackoverflow for my case:
mailx -v -S smtp=SERVER -s "$(echo -e "This is the subject\nContent-Type: text/html")" -r FROM TO < htmlmail.txt
This just returns a plain text email in my case.
So here is what I have tried so far:
Try 1:
I saw in a post to add Content-Disposition: inline.
mailx -v -S smtp=SERVER -s "$(echo -e "This is the subject v1\nContent-Type: text/html\nMIME-Version: 1.0\nContent-Disposition: inline")" -r FROM TO < htmlmail.txt
This ends up sending an html email but since the headers are included inline with the body it outputs as such:
Content-Disposition: inline Message-ID: User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello World
Try 2:
So I do not want the headers printed out in the body. So I tried to remove the Content-Disposition: inline
mailx -v -S smtp=SERVER -s "$(echo -e "This is the subject v2\nContent-Type: text/html\nMIME-Version: 1.0")" -r FROM TO < htmlmail.txt
This ends up sending a plain test email as such:
<html> <b>Hello World</b> </html>
Try 3:
Tried flip flopping content-type and mime-version
mailx -v -S SERVER -s "$(echo -e "This is the subject v3\nMIME-Version: 1.0\nContent-Type: text/html")" -r FROM TO < htmlmail.txt
I ended up receiving no email from this code
Try 4:
I saw online to try another header to help find where the issue lies. So I added the header option to set the mail priority.
mailx -v -S smtp=SERVER -s "$(echo -e "This is a subject v4\nContent-Type: text/html\nX-Priority: 1 (Highest)")" -r FROM TO < htmlmail.txt
This ended up sending a high priority email but all in plain text.
Try 5:
I added on the MIME header to the previous try
mailx -v -S smtp=SERVER -s "$(echo -e "This is a subject v5\nMIME-Version: 1.0\nContent-Type: text/html\nX-Priority: 1 (Highest)")" -r FROM TO < htmlmail.txt
This ended up sending an email with headers in the body and the priority not set to high...weird
X-Priority: 1 (Highest) Message-ID: User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello World
After all of this, I've tried many other adaptations of the above tries but they led to no new output.
So any suggestions or ideas are gladly accepted! Please keep in mind my constraints listed above...I know they limit my options but that's out of my control.
thanks for your time!