SQL Server
SQL Server
Check if an Email Was Received Digitally Signed
See more Email Object Examples
Demonstrates the read-only Chilkat Email.ReceivedSigned property, which is true if the email was originally received carrying one or more digital signatures. Knowing a message was signed is separate from knowing the signature checked out, so this example also reads SignaturesValid to report whether the signed content verified.
Background: A digital signature on an email (S/MIME) provides two things: authenticity (it was really sent by the holder of a particular certificate) and integrity (the content was not altered in transit). The sender signs a hash of the message with their private key; the recipient verifies it with the sender's public certificate.
ReceivedSigned simply tells you a signature is present — verifying it is a separate step exposed through SignaturesValid.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the read-only Email.ReceivedSigned property, which is true if this
-- email was originally received with a digital signature. Use SignaturesValid to
-- determine whether the signed content actually verified.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @email, 'LoadEml', @success OUT, 'qa_data/eml/signed.eml'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
RETURN
END
EXEC sp_OAGetProperty @email, 'ReceivedSigned', @iTmp0 OUT
IF @iTmp0 = 1
BEGIN
PRINT 'This email was received with a digital signature.'
EXEC sp_OAGetProperty @email, 'SignaturesValid', @iTmp0 OUT
IF @iTmp0 = 1
BEGIN
PRINT 'All signatures are valid.'
END
ELSE
BEGIN
PRINT 'One or more signatures are NOT valid.'
END
END
ELSE
BEGIN
PRINT 'This email was not signed.'
END
-- Note: Paths such as "qa_data/..." are relative local filesystem paths,
-- relative to the current working directory of the running application.
EXEC @hr = sp_OADestroy @email
END
GO