DataFlex
DataFlex
Set the Signing Certificate for an Email
See more Email Object Examples
Demonstrates the Chilkat Email.SetSigningCert method, which sets the certificate (with access to its private key) used to create a digital signature when sending signed email. This example loads the signing certificate from a PFX, sets it, and enables signed sending.
Background: Signing uses your own private key (the opposite of encrypting, which uses the recipient's public key), so the signing certificate must include private-key access. A PFX (PKCS#12) file bundles the certificate and its private key together, which is why it is loaded here with
LoadPfxFile. If the certificate and key are in separate files, use SetSigningCert2 instead.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoEmail
Variant vCert
Handle hoCert
String sTemp1
Move False To iSuccess
// Demonstrates the SetSigningCert method, which sets the certificate (with access to its
// private key) used for creating a digital signature when sending signed email.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Signed email"
Set ComBody Of hoEmail To "This message will be sent with a digital signature."
Set ComFrom Of hoEmail To "alice@example.com"
Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
// Load a signing certificate together with its private key from a PFX file.
Get Create (RefClass(cComChilkatCert)) To hoCert
If (Not(IsComObjectCreated(hoCert))) Begin
Send CreateComObject of hoCert
End
Get ComLoadPfxFile Of hoCert "qa_data/certs/signer.pfx" "pfx_password" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoCert To sTemp1
Showln sTemp1
Procedure_Return
End
// Set the certificate used to create the signature.
Get pvComObject of hoCert to vCert
Get ComSetSigningCert Of hoEmail vCert To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
// Request that the email be sent with a digital signature.
Set ComSendSigned Of hoEmail To True
Showln "Signing certificate set."
// Note: The path "qa_data/certs/signer.pfx" is a relative local filesystem path,
// relative to the current working directory of the running application.
End_Procedure