Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Cert

li_Success = 0

//  Demonstrates the SetSigningCert method, which sets the certificate (with access to its
//  private key) used for creating a digital signature when sending signed email.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "Signed email"
loo_Email.Body = "This message will be sent with a digital signature."
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")

//  Load a signing certificate together with its private key from a PFX file.
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

li_Success = loo_Cert.LoadPfxFile("qa_data/certs/signer.pfx","pfx_password")
if li_Success = 0 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Email
    destroy loo_Cert
    return
end if

//  Set the certificate used to create the signature.
li_Success = loo_Email.SetSigningCert(loo_Cert)
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_Cert
    return
end if

//  Request that the email be sent with a digital signature.
loo_Email.SendSigned = 1

Write-Debug "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.


destroy loo_Email
destroy loo_Cert