Perl Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Perl Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML Conversion
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
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

Load MIME (or S/MIME) and Send as Email

Demonstrates how to load a MIME file and send it as email.

 Chilkat Perl Module Downloads for Windows, Linux, and MAC OS X

use chilkat();

$mime = new chilkat::CkMime();
$mailman = new chilkat::CkMailMan();

#  Any string argument automatically begins the 30-day trial.
$success = $mime->UnlockComponent("30-day trial");
if ($success != 1) {
    print $mime->lastErrorText() . "\n";
    exit;
}

#  Any string argument automatically begins the 30-day trial.
$success = $mailman->UnlockComponent("30-day trial");
if ($success != 1) {
    print $mailman->lastErrorText() . "\n";
    exit;
}

#  Set the SMTP server.
$mailman->put_SmtpHost("smtp.chilkatsoft.com");

#  Set the SMTP login/password (if required)
$mailman->put_SmtpUsername("myUsername");
$mailman->put_SmtpPassword("myPassword");

#  Load the MIME (or S/MIME) from a file:
$success = $mime->LoadMimeFile("edifact_smime.txt");
if ($success != 1) {
    print $mime->lastErrorText() . "\n";
    exit;
}

$fromAddr = 'admin@chilkatsoft.com';
$recipient = 'support@chilkatsoft.com';

#  Add email header fields to the MIME:
$mime->AddHeaderField("From",$fromAddr);
$mime->AddHeaderField("To",$recipient);
$mime->AddHeaderField("Subject","Here is my EDIFACT signed and encrypted...");

#  We want a Date header with the current date/time.  The email object
#  automatically generates it.  Therefore we'll create an email object and then
#  copy the Date header:
$email = new chilkat::CkEmail();
$dateStr = $email->getHeaderField("Date");
$mime->AddHeaderField("Date",$dateStr);

#  It is not necessary to save the MIME to a file.
#  We're doing it here just to have a look at the .eml in a text editor...
$success = $mime->SaveMime("email.eml");
if ($success != 1) {
    print $mime->lastErrorText() . "\n";
    exit;
}

#  Now send the MIME via SMTP:
$mimeContent = $mime->getMime();
$success = $mailman->SendMime($fromAddr,$recipient,$mimeContent);
if ($success != 1) {
    print $mailman->lastErrorText() . "\n";
    exit;
}

$success = $mailman->CloseSmtpConnection();
if ($success != 1) {
    print "Connection to SMTP server not closed cleanly." . "\n";
}

print "Mail Sent!" . "\n";
 

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