Perl Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Perl Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
Signatures
SMTP
Socket / SSL
Spider
SFTP
SSH Key
SSH
SSH Tunnel
Tar
HTTP Upload
XML
XMP
Zip

More Examples...
String
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

Send Email with Zipped Attachments

Chilkat Module for Perl 5.8.*

Chilkat Module for Perl 5.10.*

Chilkat Module for Perl 5.8.* (x64)

Chilkat Module for Perl 5.10.* (x64)

Perl example script to create an email with attachments and then convert the attachments to a single .zip attached file and mail.

# file: ZipEmailAttachments.pl

# Perl script showing how to add attachments to an email and convert
# them to a single .zip attached Zip archive.

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 email with a .zip attachment from Perl');
$email->put_Body('This message with Zip attachment 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');

# Add some attachments as per our previous example (EmailAttachments.pl)    
$contentType = new chilkat::CkString();
$success = $email->AddFileAttachment('exampleData/hamlet.xml',$contentType);
$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');

# You could send the email at this point in the code by calling mailman.SendEmail.
# If you did, your email would have 3 attachments: test1.txt, test2.txt, and hamlet.xml
# However, you could first call email.ZipAttachments like this:
$email->ZipAttachments('myAttachments.zip');

# myAttachments.zip is the name of the attachment that will appear in the email.
# After calling ZipAttachments, your email will contain 1 attachment 
# (myAttachments.zip) and within it there are three files: 
# test1.txt, test2.txt, and hamlet.xml.   

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






 

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

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