<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.iwillfearnoevil.com/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Bash-email-with-attachments</id>
	<title>Bash-email-with-attachments - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.iwillfearnoevil.com/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Bash-email-with-attachments"/>
	<link rel="alternate" type="text/html" href="https://wiki.iwillfearnoevil.com/mediawiki/index.php?title=Bash-email-with-attachments&amp;action=history"/>
	<updated>2026-05-08T15:51:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.2</generator>
	<entry>
		<id>https://wiki.iwillfearnoevil.com/mediawiki/index.php?title=Bash-email-with-attachments&amp;diff=39&amp;oldid=prev</id>
		<title>Chubbard: /* Send simple inline email */</title>
		<link rel="alternate" type="text/html" href="https://wiki.iwillfearnoevil.com/mediawiki/index.php?title=Bash-email-with-attachments&amp;diff=39&amp;oldid=prev"/>
		<updated>2021-10-15T23:13:14Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Send simple inline email&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:13, 15 October 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l76&quot;&gt;Line 76:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 76:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that $1 is the detail information to append to the message body&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that $1 is the detail information to append to the message body&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;In general, bsd-mailx seems the most reliable&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;send_email() {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;send_email() {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff::1.12:old-38:rev-39 --&gt;
&lt;/table&gt;</summary>
		<author><name>Chubbard</name></author>
	</entry>
	<entry>
		<id>https://wiki.iwillfearnoevil.com/mediawiki/index.php?title=Bash-email-with-attachments&amp;diff=38&amp;oldid=prev</id>
		<title>Chubbard: Created page with &quot;====Mail with attachments==== # Install uuencode and sendmail binaries &lt;pre&gt; function fappend {     echo &quot;$2&quot;&gt;&gt;$1; }  send_email2 () { local EMAIL=&quot;${2}&quot; FILE2=&quot;/tmp/${RANDOM}...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.iwillfearnoevil.com/mediawiki/index.php?title=Bash-email-with-attachments&amp;diff=38&amp;oldid=prev"/>
		<updated>2021-10-15T23:11:42Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;====Mail with attachments==== # Install uuencode and sendmail binaries &amp;lt;pre&amp;gt; function fappend {     echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1; }  send_email2 () { local EMAIL=&amp;quot;${2}&amp;quot; FILE2=&amp;quot;/tmp/${RANDOM}...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;====Mail with attachments====&lt;br /&gt;
# Install uuencode and sendmail binaries&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function fappend {&lt;br /&gt;
    echo &amp;quot;$2&amp;quot;&amp;gt;&amp;gt;$1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
send_email2 () {&lt;br /&gt;
local EMAIL=&amp;quot;${2}&amp;quot;&lt;br /&gt;
FILE2=&amp;quot;/tmp/${RANDOM}mail_msg.txt&amp;quot;&lt;br /&gt;
echo -e &amp;quot;${1}&amp;quot; &amp;gt; ${FILE2}&lt;br /&gt;
local FAILED=&amp;quot;${3}&amp;quot;&lt;br /&gt;
local TOTAL=&amp;quot;${4}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
TOEMAIL=&amp;quot;${EMAIL}&amp;quot;&lt;br /&gt;
if [ -z &amp;quot;${EMAIL}&amp;quot; ];then&lt;br /&gt;
  TOEMAIL=&amp;quot;chubbard@iwillfearnoevil.com&amp;quot;;&lt;br /&gt;
fi&lt;br /&gt;
FREMAIL=&amp;quot;monitor@$(hostname).DOMAIN.COM&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
#  These likely will be variables in the script&lt;br /&gt;
SUBJECT=&amp;quot;Monitored host list for ${FILE} Failed: ${FAILED} ${TOTAL}&amp;quot;;&lt;br /&gt;
local ADDITIONAL=&amp;quot;Attached is the list of all checked hosts&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MSGBODY=&amp;quot; ${ADDITIONAL}&amp;quot;&lt;br /&gt;
ATTACHMENT=&amp;quot;${FILE2}&amp;quot;&lt;br /&gt;
MIMETYPE=&amp;quot;text/plain&amp;quot; #if not sure, use http://www.webmaster-toolkit.com/mime-types.shtml&lt;br /&gt;
&lt;br /&gt;
# DON'T CHANGE ANYTHING BELOW UNLESS YOU UNDERSTAND IT&lt;br /&gt;
TMP=&amp;quot;/tmp/tmpfil_123&amp;quot;$RANDOM;&lt;br /&gt;
BOUNDARY=`date +%s|md5sum`&lt;br /&gt;
BOUNDARY=${BOUNDARY:0:32}&lt;br /&gt;
FILENAME=`basename $ATTACHMENT`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
cat $ATTACHMENT|uuencode --base64 $FILENAME&amp;gt;$TMP;&lt;br /&gt;
sed -i -e '1,1d' -e '$d' $TMP;#removes first &amp;amp; last lines from $TMP&lt;br /&gt;
DATA=`cat $TMP`&lt;br /&gt;
&lt;br /&gt;
rm -rf $TMP;&lt;br /&gt;
fappend $TMP &amp;quot;From: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;To: $TOEMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Reply-To: $FREMAIL&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Subject: $SUBJECT&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Content-Type: multipart/mixed; boundary=\&amp;quot;&amp;quot;$BOUNDARY&amp;quot;\&amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;This is a MIME formatted message.  If you see this text it means that your&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;email software does not support MIME formatted messages.&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;--$BOUNDARY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Content-Type: text/plain; charset=ISO-8859-1; format=flowed&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Content-Transfer-Encoding: 7bit&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Content-Disposition: inline&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$MSGBODY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;--$BOUNDARY&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Content-Type: $MIMETYPE; name=\&amp;quot;$FILENAME\&amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Content-Transfer-Encoding: base64&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;Content-Disposition: attachment; filename=\&amp;quot;$FILENAME\&amp;quot;;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;$DATA&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;--$BOUNDARY--&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
fappend $TMP &amp;quot;&amp;quot;;&lt;br /&gt;
#cat $TMP&amp;gt;out.txt&lt;br /&gt;
cat $TMP| /usr/sbin/sendmail -t;&lt;br /&gt;
rm $TMP;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Send simple inline email====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that $1 is the detail information to append to the message body&lt;br /&gt;
&lt;br /&gt;
send_email() {&lt;br /&gt;
local HOST=$(hostname)&lt;br /&gt;
local FROM=&amp;quot;From: monitor@${HOST}.DOMAIN.COM&amp;quot;&lt;br /&gt;
local FAILED=&amp;quot;${3}&amp;quot;&lt;br /&gt;
local TOTAL=&amp;quot;${4}&amp;quot;&lt;br /&gt;
local ADDRESS=`/sbin/ifconfig | awk '/inet addr/ {print $2}' | sed 's/.*://g' | head -1`&lt;br /&gt;
local FILE2=&amp;quot;/tmp/${RANDOM}mail_msg.txt&amp;quot;&lt;br /&gt;
echo -e &amp;quot;${1}&amp;quot; &amp;gt; ${FILE2}&lt;br /&gt;
echo -e &amp;quot;${1}&amp;quot;&lt;br /&gt;
local SUBJECT=&amp;quot;Monitored list for something Failed: ${FAILED} Total: ${TOTAL}&amp;quot;&lt;br /&gt;
local TO=&amp;quot;${2}&amp;quot;&lt;br /&gt;
if [ -z &amp;quot;${TO}&amp;quot; ];then&lt;br /&gt;
  # local TO='ops-alert@DOMAIN.COM'&lt;br /&gt;
  local TO='chubbard@iwillfearnoevil.com'&lt;br /&gt;
fi&lt;br /&gt;
mail -a &amp;quot;${FROM}&amp;quot; -s &amp;quot;${SUBJECT}&amp;quot; ${TO} &amp;lt; ${FILE2}&lt;br /&gt;
rm -f ${FILE2}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[Category:bash]]&lt;/div&gt;</summary>
		<author><name>Chubbard</name></author>
	</entry>
</feed>