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 a .cer Certificate File for Encrypted EmailSends an encrypted email using the recipient's digital certificate from a .cer 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' -- Load the .cer file into a certificate object: DECLARE @cert int EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @cert, 'LoadFromFile', @success OUT, 'comodoChilkat.cer' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- 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 encrypted' EXEC sp_OASetProperty @email, 'Body', 'This is a digitally encrypted mail' EXEC sp_OASetProperty @email, 'From', 'Chilkat Support <support@chilkatsoft.com>' EXEC sp_OAMethod @email, 'AddTo', NULL, 'Comodo Test', 'comodo@chilkatsoft.com' -- Indicate that the email is to be sent encrypted. EXEC sp_OASetProperty @email, 'SendEncrypted', 1 -- Specify the certificate: EXEC sp_OAMethod @email, 'SetEncryptCert', NULL, @cert EXEC sp_OAMethod @mailman, 'SendEmail', @success OUT, @email IF @success <> 1 BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END ELSE BEGIN PRINT 'Mail Sent!' END END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.