![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Go) S/MIME Encrypt .eml without SendingSee more Email Object ExamplesDemonstrates how to encrypt an email using the recipient's digital certificate. This example just encrypts, and does not send the email.
success := false // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. email := chilkat.NewEmail() success = email.LoadEml("c:/temp/email/unencrypted.eml") if success == false { fmt.Println(email.LastErrorText()) email.DisposeEmail() return } // The email content is encrypted using AES with a 256-bit key, operating in GCM mode, which provides authenticated encryption. email.SetPkcs7CryptAlg("aes-gcm") email.SetPkcs7KeyLength(256) email.SetOaepPadding(true) email.SetOaepHash("sha256") email.SetOaepMgfHash("sha256") cert := Cert_Ref.html">chilkat.NewCert() success = cert.LoadFromFile("c/temps/cert/recipient.cer") if success == false { fmt.Println(cert.LastErrorText()) email.DisposeEmail() cert.DisposeCert() return } email.SetSendEncrypted(true) email.SetEncryptCert(cert) sbSmime := StringBuilder_Ref.html">chilkat.NewStringBuilder() // The mailman object applies the encryption by rendering the email according to the instructions (property settings) provided in the email object. // No email is sent. mailman := MailMan_Ref.html">chilkat.NewMailMan() success = mailman.RenderToMimeSb(email,sbSmime) if success == false { fmt.Println(mailman.LastErrorText()) email.DisposeEmail() cert.DisposeCert() sbSmime.DisposeStringBuilder() mailman.DisposeMailMan() return } success = sbSmime.WriteFile("c:/temp/encryptedEmail.eml","utf-8",false) if success == false { fmt.Println(mailman.LastErrorText()) email.DisposeEmail() cert.DisposeCert() sbSmime.DisposeStringBuilder() mailman.DisposeMailMan() return } fmt.Println("Success!") email.DisposeEmail() cert.DisposeCert() sbSmime.DisposeStringBuilder() mailman.DisposeMailMan() |
||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.