AutoIt Requires Chilkat v11.0.0+
AutoIt
Sign and encrypt an email with S/MIME
See more Email Object Examples
Use the sender’s signing PFX and the recipient’s public RSA certificate with with-attachments.eml, which has one recipient. Supply your own signing-key password from a credential store. Render to bytes to apply both S/MIME operations without connecting to SMTP.
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oEmail = ObjCreate("Chilkat.Email")
$bSuccess = $oEmail.LoadEml("with-attachments.eml")
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$oSigner = ObjCreate("Chilkat.Cert")
$bSuccess = $oSigner.LoadPfxFile("signer.pfx","SIGNER_PASSWORD")
If ($bSuccess <> True) Then
ConsoleWrite($oSigner.LastErrorText & @CRLF)
Exit
EndIf
$oRecipient = ObjCreate("Chilkat.Cert")
$bSuccess = $oRecipient.LoadFromFile("recipient.cer")
If ($bSuccess <> True) Then
ConsoleWrite($oRecipient.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oEmail.SetSigningCert($oSigner)
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oEmail.SetEncryptCert($oRecipient)
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$oEmail.SigningHashAlg = "sha256"
$oEmail.Pkcs7CryptAlg = "aes"
$oEmail.Pkcs7KeyLength = 256
$oEmail.OaepPadding = True
$oEmail.OaepHash = "sha256"
$oEmail.OaepMgfHash = "sha256"
$oEmail.SendSigned = True
$oEmail.SendEncrypted = True
$oMail = ObjCreate("Chilkat.MailMan")
$oRendered = ObjCreate("Chilkat.BinData")
$bSuccess = $oMail.RenderToMimeBd($oEmail,$oRendered)
If ($bSuccess <> True) Then
ConsoleWrite($oMail.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oRendered.WriteFile("signed-encrypted.eml")
If ($bSuccess <> True) Then
ConsoleWrite("Failed: rendered.WriteFile." & @CRLF)
Exit
EndIf
ConsoleWrite("Saved signed-encrypted.eml." & @CRLF)