February 11, 2014

Sending Emails using Templates

Here is a simple Python module to send emails using HTML/TEXT templates. Feel free to use the code.

https://github.com/ludmal/pylib

Step 1:

Create a TEXT/HTML file with the Keys as below
Hi [username],

Thank you for your registration.

Best regards,
[from]
[url]

Step 2:

Create a template passing the values to replace with the keys in template
values = {}
values['username'] = 'Ludmal de silva!'
values['from'] = 'The Team'
values['url'] = 'http://www.ludmal.com'
temp = EmailTemplate(template_name='welcome.txt', values=values)

Step 3:

Create a Mail Server
server = MailServer(server_name='smtp.gmail.com', username='', password='', port=0,   require_starttls=True)

Step 4:

Create a mail message and send the email
msg = MailMessage(from_email='ludmal@gmail.com', to_emails=['ludmal@gmail.com'], subject='Welcome')
send(mail_msg=msg, mail_server=server, template=temp)
Follow me on Twitter @ludmal

February 7, 2014

Python File Archiver

I always wanted to quickly cleanup my harddrive without manually searching files and moving them. So here is the solution, a simple File Arhicver python script which I wrote to clean up my hard drive. It will search for files older than a given time period & size (parameterized) and then move to a Arhicve folder. I'll try to improve the code when I get some free time and here is the script file, download and feel free to use it.

https://github.com/ludmal/pylib/blob/master/file_archiver