Difference between revisions of "Sendmail to send mail"

From Noah.org
Jump to navigationJump to search
Line 10: Line 10:
 
<pre>
 
<pre>
 
sendmail -t < message
 
sendmail -t < message
 +
</pre>
 +
 +
In a script you could do something like this:
 +
<pre>
 +
#!/bin/sh
 +
# This gives an example of sending an HTML message.
 +
#
 +
(
 +
echo "From: myuser@example.com"
 +
echo "To: user@example.net"
 +
echo "MIME-Version: 1.0"
 +
echo "Content-Type: multipart/mixed;"
 +
echo ' boundary="BOUNDARY"'
 +
echo "Subject: Test Message"
 +
echo ""
 +
echo "This is a MIME-encapsulated message"
 +
echo "--BOUNDARY"
 +
echo "Content-Type: text/plain"
 +
echo ""
 +
echo "This is what someone would see without an HTML capable mail client."
 +
echo ""
 +
echo "--BOUNDARY"
 +
echo "Content-Type: text/html"
 +
echo ""
 +
echo "<html>
 +
<body bgcolor='black'>
 +
<blockquote><font color='green'>GREEN</font> <font color='white'>WHITE</font> <font color='red'>RED</font></blockquote>
 +
</body>
 +
</html>"
 +
echo "--BOUNDARY"
 +
) | sendmail -t
 
</pre>
 
</pre>

Revision as of 18:52, 1 May 2007

Create a message file:

Subject: test
To: username@example.com

This is a test message.

Use sendmail to send the message:

sendmail -t < message

In a script you could do something like this:

#!/bin/sh
# This gives an example of sending an HTML message.
#
(
echo "From: myuser@example.com"
echo "To: user@example.net"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed;"
echo ' boundary="BOUNDARY"'
echo "Subject: Test Message"
echo ""
echo "This is a MIME-encapsulated message"
echo "--BOUNDARY"
echo "Content-Type: text/plain"
echo ""
echo "This is what someone would see without an HTML capable mail client."
echo ""
echo "--BOUNDARY"
echo "Content-Type: text/html"
echo ""
echo "<html>
<body bgcolor='black'>
<blockquote><font color='green'>GREEN</font> <font color='white'>WHITE</font> <font color='red'>RED</font></blockquote>
</body>
</html>"
echo "--BOUNDARY"
) | sendmail -t