Loading 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).
| C# | |
|---|---|
|
// Create a new instance of the MailMessage class.
MailMessage msg = new MailMessage("c:\\temp\\my message.eml"); // ... // Add recipient to it. msg.To.Add("someone@somedomain.com"); |
|
VB.NET | |
|---|---|
|
' Create a new instance of the MailMessage class.
Dim msg As New MailMessage("c:\temp\my message.eml") ' ... ' Add recipient to it. msg.To.Add("someone@somedomain.com") |
|
Loading an existing message:
The signed mail message should be validated to make sure the message was composed by the signer. To accomplish this, you can call the Validate method of the Smime class. To ensure the message is signed or not, you can use the IsSigned property of the MailMessage class in the ComponentSoft.Net.Mail namespace.
The following simple example shows you how to check a message to see whether it's signed or not, if it's signed we will validate the message's certificate:
| C# | |
|---|---|
|
// Create a new instance of the MailMessage class.
MailMessage msg = new MailMessage(); // Load the message from a file. msg.Load("testmessage.eml"); // Check to see whether the message is signed or not. if (msg.IsSigned) { MailSignatureValidationResult validationResult = Smime.Validate(msg); if (validationResult.Valid) Console.WriteLine("The signature is valid."); else Console.WriteLine("The signature is invalid."); Smime.Decrypt(msg); } else Console.WriteLine("The message is not signed."); |
|
VB.NET | |
|---|---|
|
' Create a new instance of the MailMessage class.
Dim msg As New MailMessage() ' Load the message from a file. msg.Load("testmessage.eml") ' Check to see whether the message is signed or not. If msg.IsSigned Then Dim validationResult As MailSignatureValidationResult = Smime.Validate(msg) If validationResult.Valid Then Console.WriteLine("The signature is valid.") Else Console.WriteLine("The signature is invalid.") End If Smime.Decrypt(msg) Else Console.WriteLine("The message is not signed.") End If |
|
Recent Comments