Sample code for 30+ languages & platforms
React Native Requires Chilkat v11.0.0+

POP3 Verify Signed (S/MIME) Email

Demonstrates how to download and verify digitally signed S/MIME email.

Chilkat React Native Downloads

React Native
import { Cert, Email, MailMan, StringTable } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const mailman = new MailMan();

  // Set the POP3 server's hostname
  mailman.mailHost = 'pop.example.com';

  // Set the POP3 login/password.
  mailman.popUsername = 'myLogin';
  mailman.popPassword = 'myPassword';

  const stUidls = new StringTable();
  try {
    await mailman.fetchUidlsAsync(stUidls);
  } catch {
    console.log(mailman.lastErrorText);
    return;
  }

  const email = new Email();
  const cert = new Cert();

  const count = stUidls.count;
  let i = 0;
  while (i < count) {
    // Download the full email.
    try {
      await mailman.fetchByUidlAsync(stUidls.stringAt(i), false, 0, email);
    } catch {
      console.log(mailman.lastErrorText);
      return;
    }

    console.log(i);
    console.log(`From: ${email.from}`);
    console.log(`Subject: ${email.subject}`);

    // The security layers of signed and/or encrypted emails
    // are automatically "unwrapped" when loaded into
    // a Chilkat email object.
    // An application only needs to check to see if an email
    // was received signed or encrypted, and then examine
    // the success/failure.  For example:
    if (email.receivedSigned) {

      console.log('This email was signed.');

      // Check to see if the signatures were verified.
      if (email.signaturesValid) {
        console.log('Digital signature(s) verified.');
        console.log(`Signer: ${email.signedBy}`);

        try {
          email.lastSignerCert(0, cert);
        } catch {
          console.log(email.lastErrorText);
          return;
        }

        console.log(`Signing cert: ${cert.subjectCN}`);
      }
    } else {
      console.log('Digital signature verification failed.');
    }

    i++;
  }

  await mailman.pop3EndSessionAsync();
}