Anyone has a demo available?
Sendmail is said to be not scalable,but it's free,so I decided to use it first for now:)
I couldn't get any of the posted solutions to work, 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
If I understand you correctly, you want to send mail in HTML format using linux sendmail command. This code is working on Unix. Please give it a 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 the sendmail configuration details, please refer to this link. Hope this helps.
This page should help - http://www.zedwood.com/article/103/bash-send-mail-with-an-attachment
It includes a script to send e-mail with a MIME attachment, ie with a HTML page and images included.
I understand you asked for sendmail but why not use the default mail? It can easily send html emails.
Works on: RHEL 5.10/6.x & 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
Found solution in http://senthilkl.blogspot.lu/2012/11/how-to-send-html-emails-using-sendemail.html
sendEmail -f "oracle@server" -t "name@domain.com" -u "Alert: Backup complete" -o message-content-type=html -o message-file=$LOG_FILE -a $LOG_FILE_ATTACH
To follow up on the previous answer using mail :
Often times one's html output is interpreted by the client mailer, which may not format things using a fixed-width font. Thus your nicely formatted ascii alignment gets all messed up. To send old-fashioned fixed-width the way the God intended, try this:
{ 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 the "Descriptive text here." line, but I have found that sometimes the first line may, depending on its contents, cause the mail program to interpret the rest of the file in ways you did not intend. Try the script with simple descriptive text first, before fine tuning the output in the way that you want.
-a option?
Cf. man page:
-a file
Attach the given file to the message.
Result:
Content-Type: text/html: No such file or directory
It's simpler to use, the -a option :
cat ~/campaigns/release-status.html | mail -s "Release Status [Green]" -a "Content-Type: text/html" to.address@company.com
来源:https://stackoverflow.com/questions/1333097/how-to-send-a-html-email-with-the-bash-command-sendmail