Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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'})?
        1;  # 2=high, 1=normal, 0=low
  $cdonts->{'BodyFormat'} = (exists $mail_props{'bodyformat'})?
        1;  # 0=html; 1=plaintext
  $cdonts->{'MailFormat'} = (exists $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)
      carp "Failed to attach '$attach_file' to this message.\n";

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

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

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://128958]
[LanX]: true it's the built up which is stressy
[choroba]: I doubt I can alter my accent beyond Amercian versus British
[marto]: you mean Scottish :P
[LanX]: your Czech accent is pretty good
[LanX]: oh you think no conference fees for Connery impersonators?
[choroba]: marto that's what I'm not sure about. I've seen Trainspotting a few times, but that's about it.
[LanX]: Scottish sounds more logical for me, more phonetic

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2018-04-23 09:38 GMT
Find Nodes?
    Voting Booth?