Delphi Examples

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

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
NTLM
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

Type Conversion

 

Article: Understanding COM References in Delphi

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

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATMAILLib2_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
mailman: TChilkatMailMan2;
success: Integer;
strCharset: String;
bEncodeBase64: Boolean;
strResponse: String;

begin
//  The mailman object is used for sending and receiving email.
mailman := TChilkatMailMan2.Create(Self);

//  Any string argument automatically begins the 30-day trial.
success := mailman.UnlockComponent('30-day trial');
if (success <> 1) then
  begin
    Memo1.Lines.Add(mailman.LastErrorText);
    Exit;
  end;

//  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 <> 1) then
  begin
    Memo1.Lines.Add(mailman.LastErrorText);
    Exit;
  end;

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 (Length(strResponse) = 0 ) then
  begin
    Memo1.Lines.Add(mailman.LastErrorText);
    Exit;
  end;

//  Expecting a 334 response...
if (mailman.LastSmtpStatus <> 334) then
  begin
    Memo1.Lines.Add(strResponse);
    Exit;
  end;

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

//  Send the existing login:
strResponse := mailman.SmtpSendRawCommand('mySmtpLogin',strCharset,bEncodeBase64);
if (Length(strResponse) = 0 ) then
  begin
    Memo1.Lines.Add(mailman.LastErrorText);
    Exit;
  end;

//  Expecting a 334 response...
if (mailman.LastSmtpStatus <> 334) then
  begin
    Memo1.Lines.Add(strResponse);
    Exit;
  end;

//  Send the existing password:
strResponse := mailman.SmtpSendRawCommand('mySmtpPassword',strCharset,bEncodeBase64);
if (Length(strResponse) = 0 ) then
  begin
    Memo1.Lines.Add(mailman.LastErrorText);
    Exit;
  end;

//  Expecting a 334 response...
if (mailman.LastSmtpStatus <> 334) then
  begin
    Memo1.Lines.Add(strResponse);
    Exit;
  end;

//  Send the new password:
strResponse := mailman.SmtpSendRawCommand('myNewSmtpPassword',strCharset,bEncodeBase64);
if (Length(strResponse) = 0 ) then
  begin
    Memo1.Lines.Add(mailman.LastErrorText);
    Exit;
  end;

//  Expecting a 250 response...
if (mailman.LastSmtpStatus <> 250) then
  begin
    Memo1.Lines.Add(strResponse);
    Exit;
  end;

ShowMessage('SMTP password changed!');

success := mailman.CloseSmtpConnection();
if (success <> 1) then
  begin
    ShowMessage('Connection to SMTP server not closed cleanly.');
  end;

end;

 

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

Mail Component · .NET Email Component · XML Parser