Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#CC++MFCDelphiFoxProJavaPerlPythonRubySQL ServerVBScript

PHP ActiveX Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3


 

 

 

 

 

 

 

 

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.

Download Chilkat Email ActiveX

<?php

//  The mailman object is used for sending and receiving email.
$mailman = new COM("Chilkat.MailMan2");

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

//  Set the SMTP server.
$mailman->SmtpHost = 'smtp.chilkatsoft.com';

//  Set the SMTP login/password (if required)
$mailman->SmtpUsername = 'myUsername';
$mailman->SmtpPassword = 'myPassword';

//  Connect and authenticate:
$success = $mailman->OpenSmtpConnection();
if ($success != true) {
    print $mailman->lastErrorText() . "\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 = false;
$strResponse = $mailman->smtpSendRawCommand('CPWD',$strCharset,$bEncodeBase64);
if (is_null($strResponse)) {
    print $mailman->lastErrorText() . "\n";
    exit;
}

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

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

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

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

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

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

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

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

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

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


?>

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

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