Sending email from IDL

(Note: This is a guest post from Eduardo Iturrate, who is not only a director of sales at Exelis VIS, but he’s also an IDL master: he created RevolutionIDL, the Source Code Generator for Beginners, Katalog, the ENVI Program Generator and the ENVI5 – Google Maps Link. Thanks, E! –MP)

The following technique uses IDL, PHP and a regular web server to send emails initiated by an IDL program. This can be useful in situations where you want IDL to notify you that it’s finished a long process.

This code uses the imaginary “webserver.com” server name. You will have to change that to your own server name, both in the IDL and PHP code.

Use a text editor to create the following file, named idlsendmail.php. Remember to change “idl@webserver.com” to an address that includes your domain name.

<?php
$to  = $_GET["email"];
$subject = "You've got mail! (from IDL)";
$message = 'This is a test of how to send email using IDL, PHP and a web server.';
$headers = 'From: idl@webserver.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 1;
?>

Upload this idlsendmail.php file to your web server. Put it in your main web directory – if you move it to a particular subdirectory, make sure to point to it in the call from IDL.

At this point, all we need to do from IDL is:

IDL> oUrl = obj_new('IDLnetUrl')
IDL> to = 'example@example.com'  ;Use your own email address here
IDL> ok = oUrl->Get(URL='http://www.webserver.com/idlsendmail.php?email='+to, /STRING_ARRAY)  ;Change webserver.com to your domain name
IDL> obj_destroy, oUrl

An email should appear in your inbox shortly afterwards. If not, check your spam folder!

Note: Fernando Santoro also has a related example of using IDL and PHP on the VIS Code Library.

About these ads

About Mark

I solve scientific programming and visualization problems with IDL.
This entry was posted in programming and tagged , , , , . Bookmark the permalink.

2 Responses to Sending email from IDL

  1. G Cianci says:

    Funny! I just wrote email.pro based on the following.

    On most unix machines (Mac OS for sure), you could also just run:
    IDL> body=’Hellow world’
    IDL> subj=’le test ‘
    IDL> addr=’a@b.com’
    IDL> spawn, ‘echo -e ” ‘ + body + ‘ ” |’ + “mailx -s ” + subj + addr

    email.pro can also deal with multiple attachments by using uuencode…

    If you’re in a rush:
    IDL> $ echo -e “Boom!” | mailx -s “IDL is done” a@b.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s