Patrick’s development blog

Encrypting mail in Thunderbird using GnuPG and Enigmail

Posted in Articles, Security by Patrick on March 17, 2009

Thunderbird is a mail user agent developed by Mozilla. GnuPG is an encryption program (free software) that uses the standard OpenPGP. This standard is based on encryption using a private and public key. The private key is used to decrypt the data while the public key is used to encrypt the data.

The Thunderbird add-on Enigmail, provides an “back-end” interface to GnuPG so the user can use Thunderbird to encrypt/decrypt mail. After installing Enigmail, generate a keypair. This will create a public and private key for the current account. The public key is meant to be distributed so other people can send mail encrypted to you. The private key however, is important NOT to distribute. Since it is used to encrypt the messages sent to you with your public key. The public key is usually uploaded to a keyserver.

It’s possible to search for public keys on the keyservers and add public keys into a local list and configure Thunderbird to encrypt all messages by default (supposing the public key to the person in question is added into your key list). Both Thunderbird, GnuPG and Enigmail, are very useful indeed : )

For more information about GnuPG and Enigmail:
http://www.gnupg.org/
http://enigmail.mozdev.org/home/index.php

Advertisements

Sending mail via SMTP in Python

Posted in Python by Patrick on June 22, 2008

SMTP (Simple Mail Transfer Protocol) is the most common protocol for sending mail. The communication in SMTP is done using TCP.
Read more about the SMTP protocol here: RFC821

Here’s an example of a simple Python program that sends a mail.

Send mail in Python using SMTP

import smtplib

addr_from = “from@mail.domain”
addr_to = “to@mail.domain”

server=smtplib.SMTP(‘smtp.server.domain’)
server.set_debuglevel(1)

msg = (“From: %s\r\nTo: %s\r\n\r\n”
% (addr_from, “, “.join(addr_to)))

msg = msg + “This is the message”

server.sendmail(addr_from, addr_to, msg)

server.quit()

‘smtp.server.domain’ specifies the SMTP server the program is going to use. You can experiment with different free SMTP servers until you find something that works. Personally, I use my ISP SMTP server.

smtplib is the module I used in order to use SMTP in Python. Information about smtplib can be found in the official Python documentation here.