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

 

 

 

 

 

 

 

Using SmtpSendRawCommand to Change Password

Demonstrates how to use the SmtpSendRawCommand method to change the SMTP user account's password for an SMTP server that supports the non-standard CPWD command.

Note: The SmtpSendRawCommand method is not yet released. To get a pre-release, send email to support@chilkatsoft.com.

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

use chilkat();

#  The mailman object is used for sending and receiving email.
$mailman = new chilkat::CkMailMan();

#  Any string argument automatically begins the 30-day trial.
$success = $mailman->UnlockComponent("30-day trial");
if ($success != 1) {
    print $mailman->lastErrorText() . "\r\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");

#  Connect and authenticate:
$success = $mailman->OpenSmtpConnection();
if ($success != 1) {
    print $mailman->lastErrorText() . "\r\n";
    exit;
}

$strCharset = "ansi";

#  Send the CPWD command and get the response.
#  Do not include a trailing CRLF (carriage-return line-feed) in the command string.

$bEncodeBase64 = 0;
$strResponse = $mailman->smtpSendRawCommand("CPWD",$strCharset,$bEncodeBase64);
if ($strResponse eq null ) {
    print $mailman->lastErrorText() . "\r\n";
    exit;
}

#  Expecting a 334 response...
if ($mailman->get_LastSmtpStatus() != 334) {
    print $strResponse . "\r\n";
    exit;
}

#  Now send the existing login/password, base64-encoded:
$bEncodeBase64 = 1;

#  Send the existing login:
$strResponse = $mailman->smtpSendRawCommand("mySmtpLogin",$strCharset,$bEncodeBase64);
if ($strResponse eq null ) {
    print $mailman->lastErrorText() . "\r\n";
    exit;
}

#  Expecting a 334 response...
if ($mailman->get_LastSmtpStatus() != 334) {
    print $strResponse . "\r\n";
    exit;
}

#  Send the existing password:
$strResponse = $mailman->smtpSendRawCommand("mySmtpPassword",$strCharset,$bEncodeBase64);
if ($strResponse eq null ) {
    print $mailman->lastErrorText() . "\r\n";
    exit;
}

#  Expecting a 334 response...
if ($mailman->get_LastSmtpStatus() != 334) {
    print $strResponse . "\r\n";
    exit;
}

#  Send the new password:
$strResponse = $mailman->smtpSendRawCommand("myNewSmtpPassword",$strCharset,$bEncodeBase64);
if ($strResponse eq null ) {
    print $mailman->lastErrorText() . "\r\n";
    exit;
}

#  Expecting a 250 response...
if ($mailman->get_LastSmtpStatus() != 250) {
    print $strResponse . "\r\n";
    exit;
}

print "SMTP password changed!" . "\n";

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


 

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