Patrick’s development blog

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”


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)


‘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.


Tetris game in Python

Posted in Uncategorized by Patrick on March 20, 2008

We’ve had a project in school this year and this is the thing I came up with. It’s a Tetris clone coded in Python using the library PyGame. Unfortunately, I won’t release the source code for this game, I have my reasons : )

I took some things into consideration when I made this game (game play wise). I’ve tried many different versions of Tetris before and become very frustruated because the rotation and block types are different than they use to be. That’s why I tried to make this Tetris clone as much alike the standard version as possible.

How to play
The block is controlled by the arrow keys and you can rotate the block with the UP-key and move the block fast with the DOWN-key.

I’ve added a web highscore system so players can upload their scores.

Download game
Windows Executable (blockbreaker.rar)

Project in school – Tetris clone

Posted in Uncategorized by Patrick on March 16, 2008

We’ve had a school project the last two terms where you have to choose a subject and write a report about it. You can also create something and write log books trough the whole process which is what I did. I saw this as an opportunity to either make something really cool, or just make it easy for myself. Guess what? I chose the latter.

The Project, Tetris
I decided to make a Tetris clone in Python and PyGame. I’ve made Tetris twice before so I thought it would be a piece of cake. First of all, I had never tried Python before when I started this project, but that part was quite easy. The game was quite a pain to make though and Python honestly drove me crazy sometimes. In the end I finished it though, this was about 1 week ago. I started on this project in October 2007 if I remember correctly and worked with it according to a schedule.

I tried to keep the game as simple as possible. You get points for each row you clear. It’s my first game in Python so the code is most likely terrible, i’ll live with that. I will show the game after i’ve packaged it. I added a highscore list to my website as well.

Tagged with: , , , , ,

web browser controller module in Python

Posted in Python by Patrick on March 5, 2008

I’m currently making a school project in Python and came to the point where I wanted to open my webbrowser trough my application. To my surprise, I found a module named webbrowser which is just as easy to use as lifting your arm. It only requires two lines of code.

Open specified URL in standard browser

import webbrowser“”)

More information: