Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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;
}
Comment on Mail with CDONTS
Download Code

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://128958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2015-07-02 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls