Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Using SmtpSendRawCommand to Change PasswordDemonstrates 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.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) -- The mailman object is used for sending and receiving email. DECLARE @mailman int EXEC @hr = sp_OACreate 'Chilkat.MailMan2', @mailman OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Any string argument automatically begins the 30-day trial. DECLARE @success int EXEC sp_OAMethod @mailman, 'UnlockComponent', @success OUT, '30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Set the SMTP server. EXEC sp_OASetProperty @mailman, 'SmtpHost', 'smtp.chilkatsoft.com' -- Set the SMTP login/password (if required) EXEC sp_OASetProperty @mailman, 'SmtpUsername', 'myUsername' EXEC sp_OASetProperty @mailman, 'SmtpPassword', 'myPassword' -- Connect and authenticate: EXEC sp_OAMethod @mailman, 'OpenSmtpConnection', @success OUT IF @success <> 1 BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END DECLARE @strCharset nvarchar(4000) SELECT @strCharset = 'ansi' DECLARE @bEncodeBase64 int -- Send the CPWD command and get the response. -- Do not include a trailing CRLF (carriage-return line-feed) in the command string. DECLARE @strResponse nvarchar(4000) SELECT @bEncodeBase64 = 0 EXEC sp_OAMethod @mailman, 'SmtpSendRawCommand', @strResponse OUT, 'CPWD', @strCharset, @bEncodeBase64 IF @strResponse Is NULL BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Expecting a 334 response... EXEC sp_OAGetProperty @mailman, 'LastSmtpStatus', @sTmp0 OUT IF @sTmp0 <> 334 BEGIN PRINT @strResponse RETURN END -- Now send the existing login/password, base64-encoded: SELECT @bEncodeBase64 = 1 -- Send the existing login: EXEC sp_OAMethod @mailman, 'SmtpSendRawCommand', @strResponse OUT, 'mySmtpLogin', @strCharset, @bEncodeBase64 IF @strResponse Is NULL BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Expecting a 334 response... EXEC sp_OAGetProperty @mailman, 'LastSmtpStatus', @sTmp0 OUT IF @sTmp0 <> 334 BEGIN PRINT @strResponse RETURN END -- Send the existing password: EXEC sp_OAMethod @mailman, 'SmtpSendRawCommand', @strResponse OUT, 'mySmtpPassword', @strCharset, @bEncodeBase64 IF @strResponse Is NULL BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Expecting a 334 response... EXEC sp_OAGetProperty @mailman, 'LastSmtpStatus', @sTmp0 OUT IF @sTmp0 <> 334 BEGIN PRINT @strResponse RETURN END -- Send the new password: EXEC sp_OAMethod @mailman, 'SmtpSendRawCommand', @strResponse OUT, 'myNewSmtpPassword', @strCharset, @bEncodeBase64 IF @strResponse Is NULL BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Expecting a 250 response... EXEC sp_OAGetProperty @mailman, 'LastSmtpStatus', @sTmp0 OUT IF @sTmp0 <> 250 BEGIN PRINT @strResponse RETURN END PRINT 'SMTP password changed!' EXEC sp_OAMethod @mailman, 'CloseSmtpConnection', @success OUT IF @success <> 1 BEGIN PRINT 'Connection to SMTP server not closed cleanly.' END END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.