Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Send Already-Signed MIME w/ SendMimeDemonstrates how to use SendMime to send an already-signed MIME message.
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.chilkatsoft.com' -- 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', 'Chilkat Admin <admin@chilkatsoft.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, 'chilkat.pfx', 'myPassword' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @certStore, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END DECLARE @cert int EXEC sp_OAMethod @certStore, 'FindCertBySubject', @cert OUT, 'Chilkat Software, Inc.' IF @cert Is NULL BEGIN EXEC sp_OAGetProperty @certStore, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- This example will use the cert from the certStore... EXEC sp_OAMethod @email, 'SetSigningCert', NULL, @cert -- Render the email to signed-MIME. This is where the private -- key is accessed and the signing happens. DECLARE @signedMime nvarchar(4000) EXEC sp_OAMethod @mailman, 'RenderToMime', @signedMime OUT, @email -- Now send the already-signed MIME: DECLARE @fromAddr nvarchar(4000) DECLARE @recipients nvarchar(4000) SELECT @fromAddr = 'admin@chilkatsoft.com' SELECT @recipients = 'support@chilkatsoft.com, matt@chilkatsoft.com' EXEC sp_OAMethod @mailman, 'SendMime', @success OUT, @fromAddr, @recipients, @signedMime 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.