Sending MAPI email with PERL in ClearQuest

Posted on 2007-10-03
Last Modified: 2008-01-09
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.Session")
        or die "Failed to create a new MAPI Session!";

        # Logon to server
   my $res = $mapisession->Logon("OUTLOOK");
        die "Could not log on to exchange server!" if ($res);
   # Create a new message
   my $msg = $mapisession->Outbox->Messages->Add();
   # Add the recipient and resolve the address
       my $recipient = $msg->Recipients->Add();
        $recipient->{Name} = $myvar;
        # Add your text
        $msg->{Subject} = "Fat Client Test";
        $msg->{Text} = qq/
                Email test ....
                will this work?
                        Fred and Barney
        # Send the email
        $msg->Send(0, 0, 0);
        # Log off
Question by:mschwade
    LVL 39

    Accepted Solution

    my $recipient2 = $msg->Recipients->Add();
    $recipient2->{Name} = $myvar2;
    ... and so on for more recipients

    LVL 1

    Author Comment

    Thank you that worked, but is there anyway to make the 2nd recpient show up on the CC line?

    LVL 1

    Author Comment


    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;
          $rcount = $rcount+1;
    LVL 39

    Expert Comment

    According to this:
    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($myvar2, undef, 2);

    To add from an array
    foreach my $uname (@users) {
        my $recip = $msg->Recipients->Add();
        $recip->{Name} = $uname;

    LVL 1

    Author Comment

    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;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video discusses moving either the default database or any database to a new volume.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now