Key generation involves creating a pair of keys: a public key and a private key. The public key is used to encrypt the email, while the private key is used to decrypt it. This process is known as Public Key Infrastructure (PKI). When an email is sent, the sender encrypts it using the recipient's public key. Only the recipient's private key can decrypt the email, ensuring that only the intended recipient can read the message.