From: Greg Ercolano <erco@(email surpressed)>
Subject: Re: Customised Donemail?
   Date: Thu, 12 Mar 2015 15:39:57 -0400
Msg# 2388
View Complete Thread (3 articles) | All Threads
Last Next
On 06/20/07 20:32, Greg Ercolano wrote:
> 	To use it, save the perl script somewhere, and setup the job's
> 	'jobdonecommand' to invoke it with the email addresses to send
> 	the email to, e.g.:
> 
> jobdonecommand perl //yourserver/some/directory/MyCustomDonemail.pl foo@(email surpressed) bar@(email surpressed)
> 
> 	Here's the script:
> 
> ---- snip
> #!/usr/bin/perl -w
> 
> #
> # SEND EMAIL TO USER(S) WHEN JOB IS DONE
> #
> #     Invoke this script via 'jobdonecommand'.
> #     Any arguments are treated as email addresses.
> #
> [..]

    Would like to update this old thread to include some SSL
    examples for sending email, as some servers need SSL
    authentication to send email.

    In such a case, with perl you can use the Net::SMTP::SSL module, e.g.
    something like:

---- snip
#!/usr/bin/perl

# smtp-ssl with auth
use warnings;
use strict;
use Net::SMTP::SSL;

# SERVER CONFIG
my $server     = 'your.smtp.server.com';
my $user       = 'authuser@(email surpressed)';
my $pass       = 'somepass';

# MESSAGE HEADER INFO
my $to         = 'them@(email surpressed)';
my $from_name  = 'John Q Public';
my $from_email = 'johnq@(email surpressed)';
my $subject    = 'Test message';

# CONNECT TO SERVER
my $smtps = Net::SMTP::SSL->new($server,
                                Port => 465,
                                DEBUG => 1 ) or warn "$!\n";
defined ($smtps->auth($user, $pass)) or die "Can't authenticate: $!\n";

# SEND MESSAGE
$smtps->mail($from_email);
$smtps->to($to);
$smtps->data();
$smtps->datasend("To: $to\n");
$smtps->datasend("From: \"$from_name\" <$from_email>\n");
$smtps->datasend("Subject: $subject\n");
$smtps->datasend("\n");			# empty line separates header from body
$smtps->datasend("Your multiline message goes here.\n");
$smtps->dataend();
$smtps->quit();
print "done\n";
---- snip

	See the perl docs for the Net::SMTP::SSL module for more info.

	And here's a python technique, e.g.

---- snip
import smtplib

# SERVER
server     = 'your.server.com'
mailuser   = 'authuser@(email surpressed)'	# if auth needed
mailpasswd = 'somepass'			# if auth needed

# MESSAGE HEADER
from_addr  = 'us@(email surpressed)'
to_addr    = 'them@(email surpressed)'
subject    = 'Test message'
msg        = "From: %s\nTo: %s\nSubject: %s\n\n" % ( from_addr, to_addr, subject)
msg       += "Your multiline msg here.\nLine two.\n"

# CONNECT TO SERVER, AUTHENTICATE
m = smtplib.SMTP_SSL(server, port=465)
m.login(mailuser, mailpasswd)		# if auth needed
m.set_debuglevel(1)

# SEND MESSAGE
m.sendmail(from_addr, to_addr, msg)
m.quit()
---- snip

	See the python docs for smtplib for more.


-- 
Greg Ercolano, erco@(email surpressed)
Seriss Corporation
Rush Render Queue, http://seriss.com/rush/

Skype: ercolano77
  Tel: (Tel# suppressed)ext.23
  Fax: (Tel# suppressed)
  Cel: (Tel# suppressed)


Last Next