Saml Features

Create Message

There are two type of mail message: MIME and Non-MIME. It's recommended to create mail messages in MIME format since most email clients today are MIME compatible. This section illustrates how to create mail messages.

Create a simple message

In order to use the classes in the Ultimate Mail library, you have to add references to ComponentPro.Mail.dll, ComponentPro.Common.dll, and ComponentPro.Network.dll assemblies to your project.

The examples below show how to create a simple mail message using the UltimateMail component:

Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailCreate.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailCreate.vb'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailEncrypting.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailEncrypting.vb'.

Create an encrypted mail message

To encrypt a mail message, you only need an X509 certificate (private key is not required). Certificate can be loaded from a certificate file (.cer or .der extensions), from a PKCS#12 encrypted file (.pfx or .p12 extensions), or get it from the Window Certificate Store.

Only the message body is encrypted, the top-level headers are not encrypted.The example below shows how to encrypt a mail message.

Create an encrypted and signed mail message

A message can be both encrypted and signed. This ensures to the sender that only the intended recipients are able to read the message content, and to the recipient that the message was indeed sent by the sender.

There are two ways to produce a message that is both encrypted and sign:

  • Sign the message first, then encrypt the signed message.
  • Encrypt the message first, then sign the encrypted message.

In the first case, no one but the recipient will be able to validate the signature and access the message content. In the second case, no one but the recipient will be able to access the message content, but anyone will be able to validate the signature. Both ways have their pros and cons, but there is a very strong reason to prefer the first way: Outlook Express does not handle the second way correctly, and reports the correct signature is not valid.

Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailEncryptingAndSigning.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailEncryptingAndSigning.vb'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MHTMail.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MHTMail.vb'.

Create an e-mail message containing embedded resources

The code snippet below shows you how to create an e-mail message and add an image from local disk as a LinkedResource object:

Create a message that has read receipt request

It is often needed to make sure recipients received your email. This task can easily be done by adding addresses that will receive the notification to your message using the Headers property of the MailMessage class.

Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailCreateReceiveRequest.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailCreateReceiveRequest.vb'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailCreateReply.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailCreateReply.vb'.

Create a reply message

To reply to a message, you can simply create a new message object including the subject of the original message with 'RE: ' placed at the beginning. The following code example shows you how to do that.

Include original message as attachment

To include the original message as an attachment, simply create a new Attachment object containing the original message and add it to a new message. The following code example shows you how to do that.

Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailCreateOrg.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailCreateOrg.vb'.

Load and Save message

Ultimate Mail lets you load and save mail messages easily.

Load an existing message

With UltimateMail component, you can quickly create a new message from many sources such as from local disk file or data stream. The following sample illustrates how to create load an existing message (.EML). From version 5.0, Ultimate Mail can also load Outlook MSG file format.

Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailLoad.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailLoad.vb'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailCreateSave.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailCreateSave.vb'.

Saving a message

MailMessage class provides a set of convenient methods for saving a message to either a local file or write it into a data stream. The following example shows you how to create a new mail message and save it to a local file:

Extract attachments from a message

Attachments in a mail message can either be extracted to file or stream object. The example below shows how to load a mail message and save its attachments to disk:

Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailExtractAttachment.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailExtractAttachment.vb'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MHTExtract.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MHTExtract.vb'.

Extracting embedded resources

Linked resources in a mail message can either be extracted to file or stream object. The example below shows how to load a mail message and save its embedded resources to disk:

Work with SHA-256

To encrypt a mail message, you need to provide a key or certificate for the encryption and call the Encrypt method of the MailMessage. See the example below for more details:

Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\MailEncryptLoaded.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\MailEncryptLoaded.vb'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\CreatingMetadata_SP_ADFS.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\CreatingMetadata_SP_ADFS.vb'.

Generate SAML Metadata for ADFS

The following example demonstrates how to generate SAML Metadata for ADFS:

Advanced

This section covers some advanced features of the Ultimate SAML component.

Enable trace log

You can configure Ultimate SAML to write trace log to file, console, or any output. The information in the log file can assist with tracking down SAML issues. To enable SAML trace log in your application, add the following code segment to your application's bootstrap, usually in Application_Start event.

Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\CS\PHostVerify.cs'.
Unable to read code file 'C:\ComponentPro\Website2.0\Sites\ComponentPro\CodeExamples\Saml\VB\PHostVerify.vb'.