validate mail signature during pop3 retrieval

0 votes
asked Mar 10 by CBonnkirch (120 points)

Hello,
i need some sample code in VB (C# is ok also) for validating a mail signature while retrieving mails with pop3. In case of an invalid signature, i need to pop up a message instead of displaying the mail.

Thanks in advance
Christof

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Mar 10 by Lukas Pokorny (109,670 points)

Hello, the following code demonstrates how to achieve this:

' connect to a POP3 server and authenticate
Dim client = New Pop3()
client.Connect(serverName, serverPort, sslMode)
client.Login(userName, password)

' download a message as an instance of MailMessage
Dim message As MailMessage = client.GetMailMessage(messageSequenceNumber)

' if the message is signed, check signature validity and display
' a message box if not valid
If message.IsSigned Then
    Dim validity As MailSignatureValidity = message.ValidateSignature()
    If Not validity.Valid Then
        System.Windows.Forms.MessageBox.Show("Message signature is not valid.")
    End If
End If

Note: In an actual application, don't forget to disconnect the 'client' instance when no longer needed, otherwise the session would remain active until the instance of Pop3 is claimed by the garbage collector.

For a sample code that downloads more than one specific message, please see our Pop3Downloader sample code, which comes with Rebex Secure Mail packages.

...