Perl Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



Perl Examples

Quick Start
Perl Unicode
Perl Byte Array
Perl Certs
Perl Email
Perl Encryption
Perl FTP
HTML-to-XML
Perl HTTP
Perl IMAP
Perl MHT
Perl MIME
Perl RSA
Perl S/MIME
Perl Signatures
Perl Socket
Perl Spider
Perl Tar
Perl Upload
Perl XML
Perl XMP
Perl Zip

More Examples...
String
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

 

Send Email with Attachments

This Perl script creates an email and adds attachments from file on disk and from in-memory strings (and then sends the email).

Download Perl Programming Example Scripts

# file: EmailAttachments.pl

# Perl script showing how to send email with attachments

use chilkat;

$mailman = new chilkat::CkMailMan();
$mailman->UnlockComponent('anything for 30-day trial');

# Set the SMTP server hostname
$mailman->put_SmtpHost('smtp.comcast.net');

# If your SMTP server requires a login, set username/password
# $mailman->put_SmtpUsername('myUsername');
# $mailman->put_SmtpPassword('myPassword');

# Create a simple email
$email = new chilkat::CkEmail();
$email->put_Subject('Sending mail with attachments from Perl');
$email->put_Body('This e-mail was sent from a Perl script');
$email->put_From('Chilkat Support <support@chilkatsoft.com>');

# Add a few recipients
$email->AddTo('Matt','matt@chilkatsoft.com');
$email->AddTo('TagTooga','admin@tagtooga.com');
    
# Attachments can be added from files or in-memory data.
# Returns true if the file was added successfully.  The content-type
# is returned in the 2nd argument.  This is for the benefit of programs
# that may need it (for whatever reason), but most users do not.
$contentType = new chilkat::CkString();
$success = $email->AddFileAttachment('exampleData/hamlet.xml',$contentType);
# Any method that returns a success status
# will return false for failure and true for success.
# The last-error information can be obtained by examining the LastErrorText
# property or by calling SaveLastError on the instance of the object.
	
# You may add a text file attachment directly from a string in memory.
# AddStringAttachment2 allows for the charset encoding to be directly specified.
# AddStringAttachment automatically uses the utf-8 encoding for text file attachments.
$email->AddStringAttachment('test1.txt','This string is the content of test1.txt');
$email->AddStringAttachment2('test2.txt','This string is the content of test2.txt','iso-8859-1');

$success = $mailman->SendEmail($email);
if (! $success)
    {
	$mailman->SaveLastError('lastError.txt');	
    }





 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.