Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Send Signed Email using PFX FileDemonstrates how to send a signed email using a digital certificate w/ private key stored in a PFX file.
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 PRINT 'Component unlock failed' RETURN END -- Set the SMTP server. EXEC sp_OASetProperty @mailman, 'SmtpHost', 'smtp.comcast.net' -- Create a new email object DECLARE @email int EXEC @hr = sp_OACreate 'Chilkat.Email2', @email OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OASetProperty @email, 'Subject', 'This email is signed' EXEC sp_OASetProperty @email, 'Body', 'This is a digitally signed mail' EXEC sp_OASetProperty @email, 'From', 'TagTooga <admin@tagtooga.com>' EXEC sp_OAMethod @email, 'AddTo', NULL, 'Chilkat Support', 'support@chilkatsoft.com' -- Indicate that the email should be sent signed. EXEC sp_OASetProperty @email, 'SendSigned', 1 -- Create an instance of a certificate store object, load a PFX file, -- locate the certificate we need, and use it for signing. -- (a PFX file may contain more than one certificate.) DECLARE @certStore int EXEC @hr = sp_OACreate 'Chilkat.CertStore', @certStore OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- The 1st argument is the filename, the 2nd arg is the -- PFX file's password: EXEC sp_OAMethod @certStore, 'LoadPfxFile', @success OUT, 'tagtooga_secret.pfx', 'secret' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @certStore, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END DECLARE @cert int EXEC sp_OAMethod @certStore, 'FindCertBySubjectE', @cert OUT, 'admin@tagtooga.com' IF @cert Is NULL BEGIN EXEC sp_OAGetProperty @certStore, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- If a PFX file is known to contain a single certificate, -- you may load it directly into a Chilkat certificate object. -- This snippet of source code shows how: DECLARE @cert2 int EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert2 OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- The 1st argument is the filename, the 2nd arg is the -- PFX file's password: EXEC sp_OAMethod @cert2, 'LoadPfxFile', @success OUT, 'tagtooga_secret.pfx', 'secret' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- This example will use the cert from the certStore... EXEC sp_OAMethod @email, 'SetSigningCert', NULL, @cert -- Send a signed email. EXEC sp_OAMethod @mailman, 'SendEmail', @success OUT, @email IF @success <> 1 BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END ELSE BEGIN -- The LastErrorText property provides information -- even when successful. EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 PRINT 'Mail Sent!' END END GO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.