smtp_send.pl
A long time ago, I had modified a script written by Scott Herald @ vmguru.com that sends email from the service console. A while back Scott reworked his website and all of the downloads are gone. I intended to put it up here and forgot. Today I saw a post from Duncan Epping @ http://www.yellow-bricks.com/ that reminded me.
Duncan is hosting the script which is cool. I will also stick it here for when he decides to redo his site.
This is Duncan’s modified version which changes the MIME type from TEXT to TEXT/HTML. I would guess that is fine for everyone (plain text or html).
smtp_send.pl sends mail from ESX 2.x or ESX 3.x. It does require Lite.pm to be placed in
/usr/lib/perl5/5.8.0/MIME/, or whatever your version of perl is (ESX 2.x is 5.6.1). Also, don’t forget to open outbound 25/tcp in your service console firewall.
You can upload the file to your ESX host, /usr/local/bin is a good spot and run smtp_send.pl with no switches to see the command line options.
Download smtp_send.pl (628) here.
With this version of smtp_send is it your opinion that it should allow you to send an embedded html message?
I assume by embedded html you mean an email that has HTML content. Such as html text formatting or linked images. Not that I’ve tried it, but you should be able to format the body of the message just like a web page. Assuming your mail client will process the HTML it should work out just fine.
Jeremy,
First I would like to say thanks for the script, it works great. I use it to email log files from several ESX servers.
I do have one question, is there a way to send multiple attachments? I could tar the log files and send them in one
attachment, but I would like to view them on my blackberry so a tar file is not an option.
Thanks in advance.
Jeff
Jeff,
I quickly modified the script to support multiple attachments. Download the script again to get the new version.
To attach multiple files, use the -a or -attach option multiple times. Here is an example:
./smtp_send.pl -t jpries@abc.com -s Test -f abc@def.com -a /tmp/a.txt -a /tmp/b.txt -a /tmp/c.txt -r 192.168.1.1
Jeremy
Fantastic,
Thanks, I’ll give it a try
Jeremy gave it a shot, I only receive the last attachment (messages.txt)
My cronjob is as follows:
cp /var/log/vmkwarning /var/log/vmkwarning.txt
cp /var/log/messages /var/log/messages.txt
/usr/local/bin/smtp_send.pl -t xxx@xxx.xxx -s test -f xxx@xxx.xxx -a /var/log/vmkwarning.txt -a /var/log/messages.txt > /dev/null 2>&1
rm -f /var/log/vmkwarning.txt
rm -f /var/log/messages.txt
Jeff, I ran your script on my host and received both attachments. I wonder if you got the updated script or a cached copy of the old one. Try to download the file again, looking for MODIFY DATA: 4/9/2008 at the top of the file.
Or if you allow outbound port 80 from the host, the following will work to download it.
mv /usr/local/bin/smtp_send.pl /usr/local/bin/smtp_send.pl.old
lwp-download -a http://www.jeremypries.com/scripts/smtp_send.pl /usr/local/bin/smtp_send.pl
chmod x /usr/local/bin/smtp_send.pl
Then you may need to go update $smarthost.
Jeremy,
I had the old copy of smtp_send. It works great with multiple attachments.
Thanks for taking the time to put this together.
Much Appreciated,
Jeff