J
Jack
Hi for some reason I can send email and the target receives it with my
James mailserver via Outlook Express, but not via BLAT. I am using
user/pass authentication.. can anyone point me to a script that works
and is simple for
1- send an email directly (problem with below is email never shows up
at destination)
OR 2-controlling Outlook Express to simply send an email (Undefined
subroutine &threads::new called at outlook_api_send.pl line 83.)
Neither of the examples work below
# 1 -
use Net::SMTP;
$smtp = Net::SMTP->new("smtp.xyz.com", Timeout => 5,Port =>25);
$ret = $smtp->auth("barry","password");
if ( ! $ret ) {
printf("Authentication failed\n");
} else {
printf("Authentication succeeded\n");
}
if ( ! $smtp ) {
die "Connection to SMTP server failed\n";
}
# Start a new email, and set the From address
$smtp->mail("(e-mail address removed)");
# We're sending this to three people
@recipients = (
"(e-mail address removed)"
);
$smtp->recipient(@recipients);
# Build the mail's headers, including the From: and To: address
$headers = <<"EOH";
From: Barry <[email protected]>
To: Bill <[email protected]>
Subject: This is a test
Date: Sun, 9 Mar 2008 00:03:46 +1100
EOH
# Build the content of the mail:
$message = <<"EOM";
This is a test. Please ignore this message.
EOM
# Now send it out:
$smtp->data($headers . "\n" . $message);
# Close the connection to the SMTP server.
$smtp->quit();
############################
#2 Error: (Undefined subroutine &threads::new called at
outlook_api_send.pl line 83)
# This script sends email via Outlook and MS Exchange and works around
the MS service pack security update
# So now you don't need outlook running and you don't have to press a
button to complete sending the mail.
# The code is based on one found at the perlmonks forum. The one on
the forum had some bugs and did not work for me
# as stated with the security prompts.
#
# Created by: me
#
# Usage:
# perl domail.pl <options>
# <options>: (M) = Mandetory; (O) = Optional
#
# --email (M) target email address in full
# --to (M) target name in full
# --lead (M) Leads name in full
# --sr (M) SR number
# --cd (M) Expected Date for Completion.
use strict;
use Thread;
use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::GUI;
use Win32::GuiTest;
use IO::File;
use Getopt::Long;
use File::Basename;
use POSIX qw(tmpnam);
my $progname = basename($0);
## These variable will be used to store the command line argufromnts
my $email; #= ''; # (M) target email address in full
my $to; #= ''; # (M) target name in full
my $lead; #= ''; # (M) Leads name in full
my $sr; #= ''; # (M) SR number
my $cd; #= ''; # (M) usernafrom to log into unix box
my $true = 1;
my $false = 0;
GetOptions ("email=s" => \$email,
"to=s" => \$to,
"lead=s" => \$lead,
"sr=s" => \$sr,
"cd=s" => \$cd);
sub usage
{
print("\nUsage:");
print("\n\tperl domail.pl <options>");
print("\n");
print("\n\t<options>: (M) = Mandetory; (O) = Optional");
print("\n");
print("\n\t--email (M) target email address in full");
print("\n\t--to (M) target name in full");
print("\n\t--lead (M) Leads name in full");
print("\n\t--sr (M) SR number");
print("\n\t--cd (M) Expected Completion Date.");
print("\n");
print("\n\texample:");
print("\n\tperl $progname -email \"receiver\@mycompany.com\" -to
\"Mr Receiver\" -lead \"Mr Lead\" -sr SR0000000 -cd \"Friday 13 May
2005\"");
print("\n");
print("\n");
}
sub chkOpts
{
my $status = 1;
unless (defined $email) {print ("\nRecepient email is not
defined"); $status = 0;}
unless (defined $to) {print ("\nRecipient name is not
defined"); $status = 0;}
unless (defined $lead) {print ("\nLeads name is not
defined"); $status = 0;}
unless (defined $sr) {print ("\nSR in question is not
defined"); $status = 0;}
unless (defined $cd) {print ("\nExpected Completion Date is
not defined"); $status = 0;}
if (!$status) {usage(); exit;}
}
my $thr1 = Thread->new(\&handleOutlookSecurity);
sub findSecurityWindow
# this method detects whether a security window popped up in Outlook.
If it is
# the case, it needs to be processed so that the script can be
executed.
# Else it'll pend.
{
my $messageClass = "#32770";
my $winName = "Microsoft Outlook";
return Win32::GUI::FindWindow($messageClass,$winName);
}
sub clearSecurityWindow
# this method brings the security window on top of all the others,
hence focusing it
# and sends it a series of keystrokes in order to validate it.
{
my $securityHandle = shift;
while ($securityHandle!=Win32::GUI::GetForegroundWindow())
{
Win32::GUI::SetForegroundWindow($securityHandle);
Win32::GUI::Enable($securityHandle);
}
# now send key sequence that will allow maximum time for code to
run
# The sequence is as follows : initially the no button is
focused...
# One tab brings us to cancel, another tab to the time tick box
# a spacebar hit will tick the box. Then a tab will select the drop-
down
# list in order for us to choose the time length. One more tab
brings us to Yes. A keypress on the End key will
# select maximum time. Then a return key will validate our choice
# 2 tabs - spacebar - 2 tab - one end - one return
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{SPACEBAR}");
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{END}");
Win32::GuiTest::SendKeys("{ENTER}");
}
sub clearSecurityWindow2
# this method does the same as clearSecurityWindow but handles the
second security window.
{
my $securityHandle = shift;
while ($securityHandle!=Win32::GUI::GetForegroundWindow())
{
Win32::GUI::SetForegroundWindow($securityHandle);
Win32::GUI::Enable($securityHandle);
}
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{ENTER}");
}
sub handleOutlookSecurity
{
# We don't need to sleep but just to be safe
sleep 3;
my $securityHandle = 0;
while (not ($securityHandle)) # detects Outlook's popup window
that asks whether access should be granted to
{
$securityHandle = findSecurityWindow(); # wait for security
window to pop-up...
}
# window has been found - clear it
clearSecurityWindow($securityHandle);
# We need the "Yes" button to be active
sleep 10;
$securityHandle = 0;
while (not ($securityHandle))
{
$securityHandle = findSecurityWindow(); # wait for security
window to pop-up...
}
# window has been found - clear it
clearSecurityWindow2($securityHandle);
}
sub main
{
# init OLE, COINIT_OLEINITIALIZE required when using MAPI.Session
objects
Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
die Win32::OLE->LastError(),"\n" if Win32::OLE->LastError( );
# Create a new MAPI session
my $session = Win32::OLE->new('MAPI.Session') or die "Failed to
create a new MAPI Session!";
# Logon to server
my $res = $session->Logon('MS Exchange
Settings','password','False');
die "Could not log on to exchange server!" if ($res);
# Create a new message
my $msg = $session->Outbox->Messages->Add();
# Add the recipient and resolve the address
my $recipient = $msg->Recipients->Add();
$recipient->{Name} = $email;
$recipient->Resolve();
# Add your text
$msg->{Subject} = "DCA for SR $sr";
$msg->{Text} = qq/
Hello $to.
As the Assessor\/Technical Authority for the SR $sr, you are
required to participate in its Defect Case Analysis.
Please complete in the appropriate Perspective section(s) of the
DCA tool to the best of your knowledge and ability.
The due date for completion of this task is $cd.
Please work with your Lead for this SR, $lead, and be prepared to
answer relating questions if called by the Defect Council.
Thanks you for your cooperation.
Regards
The Council
Please note that this is an auto generated email. Contact your Lead
with any questions.
/;
# Send the email
# 1st argument = save copy of message
# 2nd argument = allows user to change message w/dialog box before
sent
# 3rd argument = parent window of dialog if 2nd argument is True
$msg->Update();
$msg->Send(1, 0, 0);
# Log off
$session->Logoff();
}
chkOpts();
main();
James mailserver via Outlook Express, but not via BLAT. I am using
user/pass authentication.. can anyone point me to a script that works
and is simple for
1- send an email directly (problem with below is email never shows up
at destination)
OR 2-controlling Outlook Express to simply send an email (Undefined
subroutine &threads::new called at outlook_api_send.pl line 83.)
Neither of the examples work below
# 1 -
use Net::SMTP;
$smtp = Net::SMTP->new("smtp.xyz.com", Timeout => 5,Port =>25);
$ret = $smtp->auth("barry","password");
if ( ! $ret ) {
printf("Authentication failed\n");
} else {
printf("Authentication succeeded\n");
}
if ( ! $smtp ) {
die "Connection to SMTP server failed\n";
}
# Start a new email, and set the From address
$smtp->mail("(e-mail address removed)");
# We're sending this to three people
@recipients = (
"(e-mail address removed)"
);
$smtp->recipient(@recipients);
# Build the mail's headers, including the From: and To: address
$headers = <<"EOH";
From: Barry <[email protected]>
To: Bill <[email protected]>
Subject: This is a test
Date: Sun, 9 Mar 2008 00:03:46 +1100
EOH
# Build the content of the mail:
$message = <<"EOM";
This is a test. Please ignore this message.
EOM
# Now send it out:
$smtp->data($headers . "\n" . $message);
# Close the connection to the SMTP server.
$smtp->quit();
############################
#2 Error: (Undefined subroutine &threads::new called at
outlook_api_send.pl line 83)
# This script sends email via Outlook and MS Exchange and works around
the MS service pack security update
# So now you don't need outlook running and you don't have to press a
button to complete sending the mail.
# The code is based on one found at the perlmonks forum. The one on
the forum had some bugs and did not work for me
# as stated with the security prompts.
#
# Created by: me
#
# Usage:
# perl domail.pl <options>
# <options>: (M) = Mandetory; (O) = Optional
#
# --email (M) target email address in full
# --to (M) target name in full
# --lead (M) Leads name in full
# --sr (M) SR number
# --cd (M) Expected Date for Completion.
use strict;
use Thread;
use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::GUI;
use Win32::GuiTest;
use IO::File;
use Getopt::Long;
use File::Basename;
use POSIX qw(tmpnam);
my $progname = basename($0);
## These variable will be used to store the command line argufromnts
my $email; #= ''; # (M) target email address in full
my $to; #= ''; # (M) target name in full
my $lead; #= ''; # (M) Leads name in full
my $sr; #= ''; # (M) SR number
my $cd; #= ''; # (M) usernafrom to log into unix box
my $true = 1;
my $false = 0;
GetOptions ("email=s" => \$email,
"to=s" => \$to,
"lead=s" => \$lead,
"sr=s" => \$sr,
"cd=s" => \$cd);
sub usage
{
print("\nUsage:");
print("\n\tperl domail.pl <options>");
print("\n");
print("\n\t<options>: (M) = Mandetory; (O) = Optional");
print("\n");
print("\n\t--email (M) target email address in full");
print("\n\t--to (M) target name in full");
print("\n\t--lead (M) Leads name in full");
print("\n\t--sr (M) SR number");
print("\n\t--cd (M) Expected Completion Date.");
print("\n");
print("\n\texample:");
print("\n\tperl $progname -email \"receiver\@mycompany.com\" -to
\"Mr Receiver\" -lead \"Mr Lead\" -sr SR0000000 -cd \"Friday 13 May
2005\"");
print("\n");
print("\n");
}
sub chkOpts
{
my $status = 1;
unless (defined $email) {print ("\nRecepient email is not
defined"); $status = 0;}
unless (defined $to) {print ("\nRecipient name is not
defined"); $status = 0;}
unless (defined $lead) {print ("\nLeads name is not
defined"); $status = 0;}
unless (defined $sr) {print ("\nSR in question is not
defined"); $status = 0;}
unless (defined $cd) {print ("\nExpected Completion Date is
not defined"); $status = 0;}
if (!$status) {usage(); exit;}
}
my $thr1 = Thread->new(\&handleOutlookSecurity);
sub findSecurityWindow
# this method detects whether a security window popped up in Outlook.
If it is
# the case, it needs to be processed so that the script can be
executed.
# Else it'll pend.
{
my $messageClass = "#32770";
my $winName = "Microsoft Outlook";
return Win32::GUI::FindWindow($messageClass,$winName);
}
sub clearSecurityWindow
# this method brings the security window on top of all the others,
hence focusing it
# and sends it a series of keystrokes in order to validate it.
{
my $securityHandle = shift;
while ($securityHandle!=Win32::GUI::GetForegroundWindow())
{
Win32::GUI::SetForegroundWindow($securityHandle);
Win32::GUI::Enable($securityHandle);
}
# now send key sequence that will allow maximum time for code to
run
# The sequence is as follows : initially the no button is
focused...
# One tab brings us to cancel, another tab to the time tick box
# a spacebar hit will tick the box. Then a tab will select the drop-
down
# list in order for us to choose the time length. One more tab
brings us to Yes. A keypress on the End key will
# select maximum time. Then a return key will validate our choice
# 2 tabs - spacebar - 2 tab - one end - one return
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{SPACEBAR}");
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{END}");
Win32::GuiTest::SendKeys("{ENTER}");
}
sub clearSecurityWindow2
# this method does the same as clearSecurityWindow but handles the
second security window.
{
my $securityHandle = shift;
while ($securityHandle!=Win32::GUI::GetForegroundWindow())
{
Win32::GUI::SetForegroundWindow($securityHandle);
Win32::GUI::Enable($securityHandle);
}
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{TAB}");
Win32::GuiTest::SendKeys("{ENTER}");
}
sub handleOutlookSecurity
{
# We don't need to sleep but just to be safe
sleep 3;
my $securityHandle = 0;
while (not ($securityHandle)) # detects Outlook's popup window
that asks whether access should be granted to
{
$securityHandle = findSecurityWindow(); # wait for security
window to pop-up...
}
# window has been found - clear it
clearSecurityWindow($securityHandle);
# We need the "Yes" button to be active
sleep 10;
$securityHandle = 0;
while (not ($securityHandle))
{
$securityHandle = findSecurityWindow(); # wait for security
window to pop-up...
}
# window has been found - clear it
clearSecurityWindow2($securityHandle);
}
sub main
{
# init OLE, COINIT_OLEINITIALIZE required when using MAPI.Session
objects
Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
die Win32::OLE->LastError(),"\n" if Win32::OLE->LastError( );
# Create a new MAPI session
my $session = Win32::OLE->new('MAPI.Session') or die "Failed to
create a new MAPI Session!";
# Logon to server
my $res = $session->Logon('MS Exchange
Settings','password','False');
die "Could not log on to exchange server!" if ($res);
# Create a new message
my $msg = $session->Outbox->Messages->Add();
# Add the recipient and resolve the address
my $recipient = $msg->Recipients->Add();
$recipient->{Name} = $email;
$recipient->Resolve();
# Add your text
$msg->{Subject} = "DCA for SR $sr";
$msg->{Text} = qq/
Hello $to.
As the Assessor\/Technical Authority for the SR $sr, you are
required to participate in its Defect Case Analysis.
Please complete in the appropriate Perspective section(s) of the
DCA tool to the best of your knowledge and ability.
The due date for completion of this task is $cd.
Please work with your Lead for this SR, $lead, and be prepared to
answer relating questions if called by the Defect Council.
Thanks you for your cooperation.
Regards
The Council
Please note that this is an auto generated email. Contact your Lead
with any questions.
/;
# Send the email
# 1st argument = save copy of message
# 2nd argument = allows user to change message w/dialog box before
sent
# 3rd argument = parent window of dialog if 2nd argument is True
$msg->Update();
$msg->Send(1, 0, 0);
# Log off
$session->Logoff();
}
chkOpts();
main();