MFC Examples

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

MFC Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
Diffie-Hellman
DKIM / DomainKey
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.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
FreeBSD C++ Libraries
HP-UX C++ Libraries
BlackBerry QNX C++ Libraries
// Needs #include <CkMailMan.h>

    CkString strOut;

    //  The mailman object is used for sending and receiving email.
    CkMailMan mailman;

    //  Any string argument automatically begins the 30-day trial.
    bool success;
    success = mailman.UnlockComponent("30-day trial");
    if (success != true) {
        strOut.append(mailman.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  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 != true) {
        strOut.append(mailman.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    const char * strCharset;
    strCharset = "ansi";

    bool bEncodeBase64;

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

    const char * strResponse;

    bEncodeBase64 = false;
    strResponse = mailman.smtpSendRawCommand("CPWD",strCharset,bEncodeBase64);
    if (strResponse == 0 ) {
        strOut.append(mailman.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Expecting a 334 response...
    if (mailman.get_LastSmtpStatus() != 334) {
        strOut.append(strResponse);
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

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

    //  Send the existing login:
    strResponse = mailman.smtpSendRawCommand("mySmtpLogin",strCharset,bEncodeBase64);
    if (strResponse == 0 ) {
        strOut.append(mailman.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Expecting a 334 response...
    if (mailman.get_LastSmtpStatus() != 334) {
        strOut.append(strResponse);
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Send the existing password:
    strResponse = mailman.smtpSendRawCommand("mySmtpPassword",strCharset,bEncodeBase64);
    if (strResponse == 0 ) {
        strOut.append(mailman.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Expecting a 334 response...
    if (mailman.get_LastSmtpStatus() != 334) {
        strOut.append(strResponse);
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Send the new password:
    strResponse = mailman.smtpSendRawCommand("myNewSmtpPassword",strCharset,bEncodeBase64);
    if (strResponse == 0 ) {
        strOut.append(mailman.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Expecting a 250 response...
    if (mailman.get_LastSmtpStatus() != 250) {
        strOut.append(strResponse);
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    strOut.append("SMTP password changed!\r\n");

    success = mailman.CloseSmtpConnection();
    if (success != true) {
        strOut.append("Connection to SMTP server not closed cleanly.\r\n");
    }



    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

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

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