Sending Email from Python

10/01/06 | by turnerst [mail] | Categories: Code, Python

Below are a few code snippets I've written to send email from Python:

First is something to send an email from Python as formatted html. The example pulls the html from a web page, you could easily change that to a string or file.

Source code here.

The next script sends an email with a random jpeg attachment from a directory of pictures.

Source code here.

And finally the last script sends an email with an embedded image.

Source code here.

Python, Webdav and Microsoft Exchange

10/01/06 | by turnerst [mail] | Categories: Code, Python, General

I needed to access my firms Exchange server. The only way I could get access was through webdav. I wrote a couple of Python modules, the first was to provide an easy way to send an XML request over HTTP. Originally I was using the Micorosfts XMLHTTP COM Object on WIndows, however I wanted my code to run on LINUX and Windows, hence the need for the XMLHTTP module.

The xmlhttp module is here.

I haven't covered all webdav commands in my webdav module, just the ones I needed to use. Theres a fairly good reference to Webdav on the Micorosft Website if you need to use other commands.

The webdav module can be found here.

40th Birthday Party

10/01/06 | by turnerst [mail] | Categories: Code, Python, General

Its my 40th birthday in December and as part of the celebrations, I wanted to have a party!

At the party I wanted to have music playing (nothing new there), a slight twist is that I thought it may be good to have music videos playing. The sort of music I wanted to play was 80's - Flock of Seagulls, Tears for Fears etc, etc and also some more modern stuff Greenday etc. One way to collect the videos might be to sit watching MTV and hit record whenever a clip comes up. Another idea I had was to see what is being posted to news groups.

I found a site called Newzbin where they index all sorts of USENET content. One of those is music video clips. All that is needed after that is a program to process the XML files they provide and also a connection to a newsserver and something to UNRAR and PAR2VERIFY the files.

I wrote a little Python script to coordinate the process. You can get the script here.

Below is a checklist of what you will need if I've confused you:

  • Premium Access to Newzbin ~ 25p per week
  • Access to a newsserver ~ £2-£15 per month
  • You will need to enter your NewsServer hostname, username and password in to the Python script.
  • A version of UNRAR for your operating system
  • A version of Par2Verify and Par2Repair for your operating system. (I use Mandriva - there is an RPM package for Par2xxx available)
  • Python for your operating system (will already be installed on Mac and LINUX)
  • The code will run on any platform. You will have to change the 'rm' commands to del on Windows. Also the script assumes you have UNRAR, PAR2VERIFY and PAR2REPAIR in your search path.

To use the script, simply save a message ID file from Newzbin to a folder. Switch to that folder in a terminal / command window and run the python script e.g. python pnzb.py.

Blowfish Algorithm

09/01/06 | by turnerst [mail] | Categories: Code, Python

Python module to provide blowfish encryption / decryption.

The module was copied from Michael Gilfix's algorithm. I then added two helper functions decryptPwd and encryptPwd to make encryption and decryption easier.

Usage is as follows:

import blowfish

# Encrypting a password
encryptedPwd = blowfish.encryptPwd ('your key', 'password')

# Decrypting a password
decryptedPwd = blowfish.decryptPwd ('your key', encryptedPwd)

Link to python module:
blowfish.py

Pages: << 1 ... 16 17 18 19 20 21 22 23 24 25 26

September 2010
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
powered by b2evolution