Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Mail with CDONTS

by jgamble (Pilgrim)
on Dec 02, 2001 at 07:39 UTC ( #128958=snippet: print w/replies, xml ) Need Help??
Description: This is similar to the code in the Mail with Outlook snippet, but it uses the CDONTS library instead. CDONTS is supposed to be safer (from a physical access point of view, it is; from an internal software point of view, i'll leave that to others), but it only started becoming available with Windows 2000 and NT servers.
sub cdonts_mailer
{
  my(%mail_props) = @_;

  unless (exists $mail_props{'to'} and defined $mail_props{'to'})
  {
    carp "No Addressee to send mail to.\n";
    return 0;
  }

  #
  # Create the mail object.
  #
  my $cdonts = new Win32::OLE('CDONTS.NewMail');
  return 0 unless ($cdonts);

  #
  # Set the properties.
  #
  $cdonts->{'Subject'} = $mail_props{'subject'} || '[No Subject]';
  $cdonts->{'To'} = join(";", split(/[ ,;]+/, $mail_props{'to'}));
  $cdonts->{'Body'} = $mail_props{'body'} || "\r\n";
  $cdonts->{'From'} = $mail_props{'from'};
  $cdonts->{'Cc'} = $mail_props{'cc'};
  $cdonts->{'Bcc'} = $mail_props{'bcc'};
  $cdonts->{'Importance'} = (exists $mail_props{'importance'})?
        $mail_props{'importance'}:
        1;  # 2=high, 1=normal, 0=low
  $cdonts->{'BodyFormat'} = (exists $mail_props{'bodyformat'})?
        $mail_props{'bodyformat'}:
        1;  # 0=html; 1=plaintext
  $cdonts->{'MailFormat'} = (exists $mail_props{'mailformat'})?
        $mail_props{'mailformat'}:
        1;  # 0=Mime; 1=plaintext

  #
  # If there are any files to attach, check to see if
  # it's appropriate to do so before attaching.
  #
  foreach my $attach_file (@{ $mail_props{'attachments'} })
  {
    if ($attach_file and -f $attach_file)
    {
      $cdonts->AttachFile($attach_file);
    }
    else
    {
      carp "Failed to attach '$attach_file' to this message.\n";
    }
  }

  #
  # Send it off.
  #
  return 1 if ($cdonts->Send());

  carp "Error: '$!'";
  return 0;
}
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://128958]
help
Chatterbox?
[Corion]: Yay. Traditional finance situation averted. Bonds can be quoted in amounts (1_000_000 EUR) or per unit (1 unit). And a traditional error is to trade 2_000_000 piece when you meant to trade 2_000_000 EUR.
[Corion]: (one of my scripts simply catches high amounts and I phone people making that trade, ideally before the payment is due)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2017-03-29 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (347 votes). Check out past polls.