• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Yellow Bricks

by Duncan Epping

  • Home
  • ESXTOP
  • Stickers/Shirts
  • Privacy Policy
  • About
  • Show Search
Hide Search

Howto: Sending html email from the service console

Duncan Epping · Jan 23, 2008 ·

*** This article is from 2008, this does not work for ESXi, look at vCheck from Alan Renouf instead ***

When writing the “Checking the diskspace on your VMFS volumes” blog I assumed that most of you knew how to send an email from the service console. I received a bunch of emails from people who were interested in how to setup the html email functionality. Well, here it is:

A while back VMGuru.com hosted a script which enabled you to send email from the service console. I just browsed their site and it’s nowhere to be found. So I hosted it on my site, mind: I changed the script so that you are able to send HTML emails. This is very useful for the vdfhtml script, that’s the name I gave it… You can download the new smtp_send.pl here. All credits for smtp_send.pl go to Scott Herold and Jeremy Pries. I only changed the following:

$msg->attach(Type =>’TEXT’,
became
$msg->attach(Type =>’TEXT/HTML’,

Upload this script to /usr/local/bin, and upload Lite.pm from the MIME package to /usr/lib/perl5/5.8.0/MIME/, the “5.8.0” directory could be different on your ESX build, it depends on which version of perl is running. Now open up the firewall for smtp out to be able to send email:

esxcfg-firewall -o 25,tcp,out,SMTP

Now you can send html email with the following command, in this example I used the vdf.html ouput file as input for the body of the email.

/usr/local/bin/smtp_send.pl -t [email protected] -s “Diskspace report of the VMFS volumes” -f [email protected] -m “`cat /var/log/vdf.html`” -r 172.10.10.10
-t = Receiver
-s = Subject
-f = Sender
-m = Message body
-r = Mail relay host

You can add this line to the bottom of the vdf-vmfs script and schedule this script via the crontab. Add the following line(I assumed you named the script vdfhtml.sh) to the crontab if you want to receive this email every day at 10:00:

00 10 * * * root /usr/local/bin/vdfhtml.sh

Share it:

  • Tweet

Related

Management & Automation, Server 3.0.x, 3.5, ESX, Scripting, service console, VMware

Reader Interactions

Comments

  1. Jaime says

    23 January, 2008 at 17:10

    Thanks for posting this. I’m glad to know that I’m not the only person that didn’t know how to do this!

  2. Matt Lydy says

    23 January, 2008 at 18:16

    Thanks for posting this step by step guide! I’m so close to getting this running. Everything seems to be working fine but when it sends the email instead of displaying the table it shows ‘cat /var/log/vdf.html’

    If I go look at the vdf.html file it is correct but for some reason it isn’t displaying it. Any ideas on what I might have missed?

  3. Matt Lydy says

    23 January, 2008 at 20:29

    Woops typo in my code… I was using ‘ instead of `.

    Works perfectly now!!! Thank you!

  4. Jaime says

    25 January, 2008 at 15:47

    When I try to run the smtp_send.pl script, I get the following error:
    Undefined subroutine &Email::Date::Format::email_date called at /usr/lib/perl5/5.8.0/MIME/Lite.pm line 1098. Anyone know how I can correct this? Thanks.

  5. pnikies94 says

    5 February, 2008 at 17:18

    Hi,
    When i launch the script, i get the following error message :
    “can’t find an executable sendmail at /usr/local/bin/smtp_send.pl line 37
    Compilation failed in require at /usr/local/bin/smtp_send.pl line 37.
    BEGIN failed–compilation aborted at /usr/local/bin/smtp_send.pl line 37.”
    do i really need sendmail ?
    Thanks

  6. GNi says

    12 February, 2008 at 08:01

    If you got error: “can’t find an executable sendmail at /usr/local/bin/smtp_send.pl line 37 etc
    Check that you downloaded mime-lite version 3.01 NOT 3.021!

  7. Dinny says

    12 February, 2008 at 18:14

    If you don’t want to enable smtp on your esx server permanently – you can turn it on at the start of the script – then turn it off again at the end.

    Just add this to the start:

    # temporarily enable firewall rule to allow access to smtp

    $cmdFirewallOn = “esxcfg-firewall -o 25,tcp,out,SMTP”;
    system($cmdFirewallOn);

    and this to the end:

    # re-apply firewall to block SMTP

    $cmdFirewallOn = “esxcfg-firewall -c 25,tcp,out,SMTP”;
    system($cmdFirewallOn);

    Dinny

  8. Dinny says

    12 February, 2008 at 18:37

    Sorry,

    If you are running it from the crontab – you will need the full path:
    # temporarily enable firewall rule to allow access to smtp

    $cmdFirewallOn = “/usr/sbin/esxcfg-firewall -o 25,tcp,out,SMTP”;
    system($cmdFirewallOn);

    and

    # re-apply firewall to block SMTP

    $cmdFirewallOn = “/usr/sbin/esxcfg-firewall -c 25,tcp,out,SMTP”;
    system($cmdFirewallOn);

    Dinny

  9. Duncan Epping says

    12 February, 2008 at 19:30

    thanks guys for the additional info!

  10. virtuel says

    22 February, 2008 at 18:58

    Thanks a lot for this post. I have been searching for something like this that could integrate directly into Virtual Center and notify groups when a scheduled snapshot is done/completed.

    I however need a lot of help with this script. I am very new to the linux world and not sure what needs to be installed where. I have downloaded the necessary files as you have mentioned but how do I install the MIME package on the esx host? Also in an environment with multiple ESX hosts would I have to then install this on all my hosts or is there a way to run this from just one central location and be notified?

    Thanks for all your help and sorry if the questions are basic

  11. esxnewbie says

    19 March, 2008 at 18:26

    I’ve tried and run this got error below. I’m not sure how to edit the line options below can someone help?

    [[email protected] bin]# perl smtp_send.pl

    Usage smtp_send.pl: [-t address] [-s subject] [-m Body] [-a path] [-f address] [-r smarthost]

    -Enclose any options that contains spaces in quotes
    -All options may be shortened to one character. Ex. -t instead of -toAddress

    Options:
    -toAddress rcpt to address (required)
    -subject subect (required)
    -messageBody body (optional)
    -attach full path to attachment (optional)
    -fromAddress mail from address (optional)
    -relay smarthost/relayhost used to deliver mail. (optional)

    -If no fromAddress is specified, the address dotscocs9vmu1.co.dot.state.fl.us will be used

    -If no relay is specified, the variable smarthost.example.com in the script is used.
    You may wish to change the value of this variable to prevent need to specify it on the command line.

    As of version 0.2, script will handle message body input via a pipe. If input is received via a pipe
    and message body on command line, the command line text will precede the pipe input in the body.

  12. Duncan Epping says

    20 March, 2008 at 13:02

    this is no error, you need to fill in the options.

  13. Lee says

    31 March, 2008 at 04:39

    Is this the correct path for ESX 3.5 for MIME?
    /usr/lib/perl5/5.8.0/Encode/MIME

  14. Lee says

    7 April, 2008 at 01:33

    Well I created the MIME folder in /usr/lib/perl5/5.8.0/

    Now when I try and send an email I get the message of “permission denied”

    I am using MIME 3.0.1

    /usr/local/bin/smtp_send.pl -t [email protected] -s “This is a test from ESX” -f [email protected] -m “testing 123” -r ExchangeIP

    bash: /usr/local/bin/smtp_send.pl: Permission denied

    Firewall is open for SMTP. Same issue if I stop firewall service.

    Any advice would be appreciated.
    Thanks

  15. Lee says

    8 April, 2008 at 00:12

    Well I now have email working…. I had to add “perl”…. so the command was………
    perl smtp_send.pl -t [email protected] -s “This is a test from ESX” -f [email protected] -m “testing 123″ -r ExchangeIP

    I assume this is the standard requirement for ESX 3.5?

    Can someone please get back to me?

  16. duncan says

    8 April, 2008 at 07:19

    I actually haven’t tested it with 3.5 Lee. Will try it today or tomorrow if I can find the time.

  17. Lee says

    8 April, 2008 at 10:55

    Thanks Duncan – appreciate it. In particular if you could advise how to schedule a script that sends an html email report ran from crontab (that references a conf file for email settings etc).

    It’s a different story if you run scripts manually as you can specify a configuration file also, however I’m not sure how to do this with crontab.

    For example (using your example above)…. what if the below script needed to reference a configuration file for email settings named “email.conf” – how would you do that? Or would that be specified in vdfhtml.sh?

    00 10 * * * root /usr/local/bin/vdfhtml.sh

    Thanks once again.

  18. Duncan Epping says

    8 April, 2008 at 11:45

    I would specify it in vdfhtml.sh. that works like a charm if you specify the full path that is.

  19. jay says

    22 April, 2008 at 10:52

    how do i sent mail to multiple recepient…?
    i tried puting address seperated with ” ; ” … didnt work 🙁

  20. Duncan Epping says

    22 April, 2008 at 11:36

    try a comma “,”.

  21. Remco says

    20 May, 2008 at 10:03

    hmmm still wondering why i can’t get the HTML output in the mail: i checked and double checked the command: but i only receive a mail with the line cat /var/log/vdf.html…………

    i checked the syntax, ` instead of ‘ but: not working for me. The customer is using ESX 3.5.0 with all the latest patches…..weird!

  22. Remco says

    20 May, 2008 at 10:14

    ….fixed it ;-)…… the outpul file referenced in the send mail object, had an illegal character…

  23. Amit says

    30 June, 2008 at 17:37

    [[email protected] bin]# perl /usr/local/bin/smtp_send.pl -t [email protected] -s “Diskspace report of ESX host” -f [email protected] -m “`cat /var/log/vdf.html`” -r 165.113.1.148
    cat: /var/log/vdf.html: No such file or directory

    I get this error message, email goes through but I see a blank email. the syntax looks correct but there is definitely something wrong, I am running it on ESX 3.5

    Any help is appreciated.

  24. Amit says

    2 July, 2008 at 16:30

    Thanks for your help Duncan, It worked after running the other script first. Appreciate your help!!

  25. Bobby says

    7 July, 2008 at 19:52

    I’m running v 3.0.1 of Lite.pm in the proper location (/usr/lib/perl5/5.8.0) still getting can’t find executable sendmail at line 37… any ideas?

  26. AOPC says

    21 July, 2008 at 17:37

    When i run vdfhtml.sh outside crontab it runs fine and sends me the email with the table.
    But when i use the same script and try to scheduIe it it runs partially. In the email i see only the header and the footer. the table is missing.
    when i view the vdf.html file after it has been run manually it is proper but when it is run via crontab the table is missing . Why isn’t the script running properly when scheduling it ? Please help.

  27. Planet Malaysia says

    7 November, 2008 at 09:40

    If you getting error message like “Failed to connect to mail server: Connection refused”, please make sure you run “esxcfg-firewall -o 25,tcp,out,SMTP”

  28. jonatj says

    25 February, 2009 at 01:39

    AOPC,

    Need to add the full path to vdf in the vdfhtml.sh script. I guess the cron job environment doesn’t have the /usr/sbin in it’s path.

    …
    echo “” >> “${LOG}”
    /usr/sbin/vdf -h -P | grep -E
    …

  29. Kcm says

    17 July, 2009 at 22:53

    Duncan, do you have an updated version for use with ESX 4? The version of PERL is different on v4 so lite.pm fails.

  30. Joerg says

    18 July, 2009 at 19:06

    @Kcm,
    just fetch the missing Format.pm from CPAN and the script will works again.

    Regards
    Joerg

  31. staria says

    30 December, 2009 at 16:00

    Hi,

    When I launch the command above(/usr/local/bin/smtp_send.pl -t [email protected] ….)I got the following error:

    Can’t locate Email/Date/Format.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .) at /usr/lib/perl5/5.8.0/MIME/Lite.pm line 1092.

    But I run:
    find / -name Format.pm
    /usr/lib/vmware/esx-perl/perl5/site_perl/5.8.0/VMware/Log/Format.pm
    cp /usr/lib/vmware/esx-perl/perl5/site_perl/5.8.0/VMware/Log/Format.pm /usr/lib/perl5/5.8.0
    And I get the same error.

    Can anyone help me?

  32. sanjai says

    15 January, 2010 at 08:26

    Staria,

    The module Email::Date::Format is being used by the script but its not installed. The remedy is to install the module.

  33. Thomas says

    9 December, 2010 at 10:31

    HI

    First of all i would like to thank you for posting this. I’m looking for a way to send log per email from the ESX and this seams to be the solution.

    I see the last comments are a few month all but with some luck someone will still see my request.

    But i have errors when i start the script.

    Im using ESXI V4 and perl 5.8.8. I had to create the MIME directory in /usr/lib/perl5/5.8.8/.

    I’m using this command :
    perl /usr/local/bin/smtp_send.pl -t [email protected] -s “Test_mail_ESX” -f [email protected] -m “test” -r smtp_srv_ip

    i get the following errors :
    Unquoted string “html” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 2.
    Unquoted string “rel” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 4.
    Bareword found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 4, near “”stylesheet” href”
    (Missing operator before href?)
    Unquoted string “href” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 4.
    Bareword found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 4, near “”http://st.pimg.net/tucs/style.css” type”
    (Missing operator before type?)
    Unquoted string “type” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 4.
    Unquoted string “rel” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 6.
    Bareword found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 6, near “”alternate” type”
    (Missing operator before type?)
    Unquoted string “type” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 6.
    Bareword found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 6, near “”application/rss+xml” title”
    (Missing operator before title?)
    Unquoted string “title” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 6.
    Bareword found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 6, near “”RSS 1.0″ href”
    (Missing operator before href?)
    Unquoted string “href” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 6.
    Unquoted string “title” may clash with future reserved word at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 8.
    Number found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 8, near “&#77”
    (Missing operator before 77?)
    Number found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 8, near “&#73”
    (Missing operator before 73?)
    Number found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 8, near “&#77”
    (Missing operator before 77?)
    Number found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 8, near “&#69”
    (Missing operator before 69?)
    Bareword found where operator expected at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 10, near “var”
    (Missing semicolon on previous line?)
    Useless use of push with no values at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 11.
    Useless use of push with no values at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 12.
    Useless use of push with no values at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 13.
    Useless use of push with no values at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 14.
    Useless use of push with no values at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 15.
    syntax error at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 2, near “html>”
    syntax error at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 8, near “&#73”
    syntax error at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 8, near “&#77”
    syntax error at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 8, near “&#69”
    syntax error at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 10, near “var _gaq ”
    Type of arg 1 to push must be array (not anonymous list ([])) at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 11, near “])”
    Type of arg 1 to push must be array (not anonymous list ([])) at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 12, near “])”
    Type of arg 1 to push must be array (not anonymous list ([])) at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 13, near “])”
    Type of arg 1 to push must be array (not anonymous list ([])) at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 14, near “])”
    Type of arg 1 to push must be array (not anonymous list ([])) at /usr/lib/perl5/5.8.8/MIME/Lite.pm line 15, near “])”
    /usr/lib/perl5/5.8.8/MIME/Lite.pm has too many errors.
    Compilation failed in require at /usr/local/bin/smtp_send.pl line 37.
    BEGIN failed–compilation aborted at /usr/local/bin/smtp_send.pl line 37.

    Thank you if you can help

  34. Fernando Lopes says

    30 October, 2013 at 20:04

    Does this solution work on the ESXi 5.1?

    • Duncan Epping says

      8 April, 2014 at 16:35

      No, there is no Service Console in ESXi

  35. Michael says

    8 April, 2014 at 02:18

    Hi, I don’t find /usr/bin/perl under esxi 5.5u1 – makes it kind of hard to send emails. How can I install that? Using the image HP is providing for their/my HP ProLiant Microserver Gen8.
    Thanks in advance Michael

    • Duncan Epping says

      8 April, 2014 at 16:35

      Note, there is no service console in ESXi. This script won’t work!

Primary Sidebar

About the author

Duncan Epping is a Chief Technologist in the Office of CTO of the Cloud Platform BU at VMware. He is a VCDX (# 007), the author of the "vSAN Deep Dive", the “vSphere Clustering Technical Deep Dive” series, and the host of the "Unexplored Territory" podcast.

Upcoming Events

Feb 9th – Irish VMUG
Feb 23rd – Swiss VMUG
March 7th – Dutch VMUG
May 24th – VMUG Poland
June 1st – VMUG Belgium

Recommended Reads

Sponsors

Want to support Yellow-Bricks? Buy an advert!

Advertisements

Copyright Yellow-Bricks.com © 2023 · Log in