How to send html email using bash command "sendmail"?

Does anyone have a demo?

Sendmail, as they say, is not scalable, but it is free, so I decided to use it first of all :)

+18
linux sendmail
Aug 26 '09 at 8:09
source share
7 answers

I could not get any of the published solutions for the job, but finally found this elsewhere and it works great:

( echo "From: ${from}"; echo "To: ${to}"; echo "Subject: ${subject}"; echo "Content-Type: text/html"; echo "MIME-Version: 1.0"; echo ""; echo "${message}"; ) | sendmail -t 
+32
Apr 08 '13 at 13:01
source share

If you understand correctly, you want to send mail in HTML format using the linux sendmail command. This code works on Unix. Please, try.

 echo "From: me@xyz.com To: them@xyz.com MIME-Version: 1.0 Content-Type: multipart/alternative; boundary='PAA08673.1018277622/server.xyz.com' Subject: Test HTML e-mail. This is a MIME-encapsulated message --PAA08673.1018277622/server.xyz.com Content-Type: text/html <html> <head> <title>HTML E-mail</title> </head> <body> <a href='http://www.google.com'>Click Here</a> </body> </html> --PAA08673.1018277622/server.xyz.com " | sendmail -t 

For sendmail configuration information, see this link . Hope this helps.

+17
Aug 26 '09 at 8:24
source share

This page should help - http://www.zedwood.com/article/103/bash-send-mail-with-an-attachment

It includes a script to send email with a MIME attachment, i.e. with an HTML page and images.

+4
Aug 26 '09 at 8:13
source share

I understand that you asked for sendmail, but why not use mail by default? It can easily send html emails.

Powered by: RHEL 5.10 / 6.x and CentOS 5.8

Example:

 cat ~/campaigns/release-status.html | mail -s "$(echo -e "Release Status [Green]\nContent-Type: text/html")" to.address@company.com -v 

CodeShare: http://www.codeshare.io/8udx5

+3
Sep 18 '14 at 6:11
source share

To follow the previous answer using mail :

Often, one html output is interpreted by the client’s mailer, which cannot format things using a fixed-width font. That way, your beautifully formatted ascii alignment gets spoiled. To send an old-fashioned fixed width like God did, try the following:

 { echo -e "<pre>" echo "Descriptive text here." shell_command_1_here another_shell_command cat <<EOF This is the ending text. </pre><br> </div> EOF } | mail -s "$(echo -e 'Your subject.\nContent-Type: text/html')" to.address@company.com 

You don’t necessarily need “Descriptive text here.”, But I found that sometimes the first line, depending on its contents, can cause the mail program to interpret the rest of the file in a way that you did not. First try a script with simple descriptive text before fine-tuning the output the way you want.

+2
Nov 18 '14 at 16:26
source share

Easier to use, -a option:

 cat ~/campaigns/release-status.html | mail -s "Release Status [Green]" -a "Content-Type: text/html" to.address@company.com 
+1
Dec 04 '15 at 10:23
source share

-a option?

Cf. man page:

 -a file Attach the given file to the message. 

Result:

 Content-Type: text/html: No such file or directory 
0
Aug 18 '17 at 14:00
source share



All Articles