Difference between revisions of "Sendmail to send mail"

From Noah.org
Jump to navigationJump to search
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Engineering]]
 +
[[Category:Mail]]
 +
== mail delivery test with sendmail ==
 +
 +
This shows how to send a message from the commandline using sendmail. See also [[SMTP_test]].
  
 
Create a message file:
 
Create a message file:
Line 10: Line 15:
 
Use sendmail to send the message:
 
Use sendmail to send the message:
 
<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>

Latest revision as of 13:56, 1 October 2008

mail delivery test with sendmail

This shows how to send a message from the commandline using sendmail. See also SMTP_test.

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