Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Send Encrypted Email in C#
This is a simple example demonstrating how to send encrypted mail via an SMTP server in C#. private void SendEncrypted_Click(object sender, System.EventArgs e)
{
// Create a mailman object for sending email.
Chilkat.MailMan mailman = new Chilkat.MailMan();
mailman.UnlockComponent("UnlockCode");
mailman.SmtpHost = "smtp.earthlink.net";
// The SMTP username and password are only necessary if
// your SMTP server requires authentication.
//mailman.SmtpUsername = "myLogin";
//mailman.SmtpPassword = "myPassword";
// Create an email object
Chilkat.Email email = new Chilkat.Email();
email.Subject = "This is the subject";
email.Body = "This is the body";
email.AddTo("Chilkat Support","support@chilkatsoft.com");
email.From = "John Smith <john@chilkatsoft.com>";
// If a certificate matching the TO email address exists in
// the any of the following certificate stores, then Chilkat Mail
// will automatically find it, select it, and encrypt the email with
// it.
// 1) Local Machine Certificate Store
// 2) Current User Certificate Store
// 3) Outlook Certificate Store
//
// For more information in general, see http://www.chilkatsoft.com/smime.asp
email.SendEncrypted = true;
// You can also specifically load a certificate from a file in
// any one of the following formats:
// 1) DER encoded binary X.509 (.CER)
// 2) Base-64 encoded X.509 (.CER)
// 3) Cryptographic Message Syntax Standard - PKCS #7 Certificates (.P7B)
//Chilkat.Cert cert = new Chilkat.Cert();
//cert.LoadFromFile("myCert.cer");
//email.SetEncryptCert(cert);
Status.Text = "Sending email...";
Status.Refresh();
bool success = mailman.SendEmail(email);
if (!success)
{
Status.Text = "Send Failed, check sendError.xml";
mailman.SaveLastError("sendError.xml");
}
else
{
Status.Text = "Success!";
}
}
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.