mschwade
asked on
Sending MAPI email with PERL in ClearQuest
Here's what I am using for my code, I want to be able to add multiple people on the TO: line CC: line and resolve them: Please help!
$myvar = "Resolved Name";
use Win32::OLE;
my $mapisession = Win32::OLE->new("MAPI.Sess ion")
or die "Failed to create a new MAPI Session!";
# Logon to server
my $res = $mapisession->Logon("OUTLO OK");
die "Could not log on to exchange server!" if ($res);
# Create a new message
my $msg = $mapisession->Outbox->Mess ages->Add( );
# Add the recipient and resolve the address
my $recipient = $msg->Recipients->Add();
$recipient->{Name} = $myvar;
$recipient->Resolve();
# Add your text
$msg->{Subject} = "Fat Client Test";
$msg->{Text} = qq/
Email test ....
will this work?
Signed
Fred and Barney
/;
# Send the email
$msg->Update();
$msg->Send(0, 0, 0);
# Log off
$mapisession->Logoff();
$myvar = "Resolved Name";
use Win32::OLE;
my $mapisession = Win32::OLE->new("MAPI.Sess
or die "Failed to create a new MAPI Session!";
# Logon to server
my $res = $mapisession->Logon("OUTLO
die "Could not log on to exchange server!" if ($res);
# Create a new message
my $msg = $mapisession->Outbox->Mess
# Add the recipient and resolve the address
my $recipient = $msg->Recipients->Add();
$recipient->{Name} = $myvar;
$recipient->Resolve();
# Add your text
$msg->{Subject} = "Fat Client Test";
$msg->{Text} = qq/
Email test ....
will this work?
Signed
Fred and Barney
/;
# Send the email
$msg->Update();
$msg->Send(0, 0, 0);
# Log off
$mapisession->Logoff();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adam,
I tried this, but didn't work..
$rcount = 1;
foreach $user_name (@users) {
recipientobj = "recipient$rcount";
my $recpientobj = $msg->Recipients->Add();
$recipientobj->{Name} = $user_name;
$recipientobj->Resolve();
$rcount = $rcount+1;
}
I tried this, but didn't work..
$rcount = 1;
foreach $user_name (@users) {
recipientobj = "recipient$rcount";
my $recpientobj = $msg->Recipients->Add();
$recipientobj->{Name} = $user_name;
$recipientobj->Resolve();
$rcount = $rcount+1;
}
According to this: http://msdn2.microsoft.com/en-us/library/ms528129.aspx
you need to set the type to 2 for cc. I'm not sure how to do that, but try this:
my $recipient2 = $msg->Recipients->Add($myv ar2, undef, 2);
$recipient2->Resolve();
To add from an array
foreach my $uname (@users) {
my $recip = $msg->Recipients->Add();
$recip->{Name} = $uname;
$recip->Resolve();
}
you need to set the type to 2 for cc. I'm not sure how to do that, but try this:
my $recipient2 = $msg->Recipients->Add($myv
$recipient2->Resolve();
To add from an array
foreach my $uname (@users) {
my $recip = $msg->Recipients->Add();
$recip->{Name} = $uname;
$recip->Resolve();
}
ASKER
I figured out the CC by the code below.. But Adam, remember in adding from an array, the my $recip still needs to be different each time through the loop or it doesn't work, for example my $recip, my $recip2, etc..
my $recipient2 = $msg->Recipients->Add();
$recipient2->{Name} = $uname;
$recipient2->{Type}=1;
$recipient->Resolve();
my $recipient2 = $msg->Recipients->Add();
$recipient2->{Name} = $uname;
$recipient2->{Type}=1;
$recipient->Resolve();
ASKER
Thanks!