Java Examples

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

Java Examples

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

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
String
Byte Array
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 Java Library Downloads for Windows, Linux, and MAC OS X

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  The mailman object is used for sending and receiving email.
    CkMailMan mailman = new CkMailMan();

    //  Any string argument automatically begins the 30-day trial.
    boolean success;
    success = mailman.UnlockComponent("30-day trial");
    if (success != true) {
        System.out.println(mailman.lastErrorText());
        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) {
        System.out.println(mailman.lastErrorText());
        return;
    }

    String strCharset;
    strCharset = "ansi";

    boolean bEncodeBase64;

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

    String strResponse;

    bEncodeBase64 = boolean;
    strResponse = mailman.smtpSendRawCommand("CPWD",strCharset,bEncodeBase64);
    if (strResponse == null ) {
        System.out.println(mailman.lastErrorText());
        return;
    }

    //  Expecting a 334 response...
    if (mailman.get_LastSmtpStatus() != 334) {
        System.out.println(strResponse);
        return;
    }

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

    //  Send the existing login:
    strResponse = mailman.smtpSendRawCommand("mySmtpLogin",strCharset,bEncodeBase64);
    if (strResponse == null ) {
        System.out.println(mailman.lastErrorText());
        return;
    }

    //  Expecting a 334 response...
    if (mailman.get_LastSmtpStatus() != 334) {
        System.out.println(strResponse);
        return;
    }

    //  Send the existing password:
    strResponse = mailman.smtpSendRawCommand("mySmtpPassword",strCharset,bEncodeBase64);
    if (strResponse == null ) {
        System.out.println(mailman.lastErrorText());
        return;
    }

    //  Expecting a 334 response...
    if (mailman.get_LastSmtpStatus() != 334) {
        System.out.println(strResponse);
        return;
    }

    //  Send the new password:
    strResponse = mailman.smtpSendRawCommand("myNewSmtpPassword",strCharset,bEncodeBase64);
    if (strResponse == null ) {
        System.out.println(mailman.lastErrorText());
        return;
    }

    //  Expecting a 250 response...
    if (mailman.get_LastSmtpStatus() != 250) {
        System.out.println(strResponse);
        return;
    }

    System.out.println("SMTP password changed!");

    success = mailman.CloseSmtpConnection();
    if (success != true) {
        System.out.println("Connection to SMTP server not closed cleanly.");
    }


  }
}

 

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