Putmail


Just found this neat tool on the internet, called putmail.
It is a SMTP Client. Now, you may wonder what exactly an SMTP client is, and why you need one. Well, if you are Unix/Linux user and use tools, which follow the Unix philosophy, then you end up with tools that do one task only.

This idea reaches back to times when resources used to be rare and expensive and programmers therefore tried to spare those resources. One way to do this was to write highly modulized tools that could be combined with each other, each of them processing one task and then handing the result over to the next tool. This made it possible to get a chain of tools that combined with each other made up a whole process line.

If you use such tools for your daily mailing issues (e.g. mutt), then you will definitely need a MTA, which in the end leads up to a SMTP capable tool. Most of the people use such tools as sendmail, exim, postfix, etc. But those are Mail-Server tools, so eventually with those tools you could run full mail servers that provide mailboxes for different users, authentication functionalities, sending mails, receiving mails, and forwarding of mails. Now this is something, a mail admin would want to use for his own domain, but it may be a bit oversized for someone who just wants to do some mailing and has an account at one of the plenty free mailers, or elsewhere (besides it is even a security risk, as a SMTP server is a service that runs all the time in the background and opens ports to the internet, which make them to potential security wholes if not configured or programmed well).

But there are also other reasons why you may want to use a mail client. Let’s say you have some tasks you want to perform regularly on any computer and be informed by the results via email. Nothing’s easier than that. And as putmail is written in python it is available for any system where Python is available (this includes Windows, Mac, and a lot of more exotic systems). So you could write a small script, let’s say a batch file, or a visual basic script, using putmail to send the IP of a computer to your mail account whenever the computer restarts, giving you the ability to access your machine through the Internet wherever you are.

These are only some usages you could think of. Anyway, as always the boundaries of usage are only set by your thinking.

So the actual task of putmail is to just connect to an SMTP server, and forward a mail. That is all it does. What makes putmail an interesting choice is, that it is easy to configure.

This is what a configuration file looks like:

[config]
server = your.smtp.server.example.com
email = your.email@example.com

That is the minimum that is required. Of course, if you have a mail account somewhere, you have additional needs like, credentials, encryption, etc.

[config]
server = smtp.mail.yahoo.de
email = pygospa@yahoo.de
username = pygospa
password = ***
port = 587

This setup will work for anybody using a yahoo! account.
Simple as that.
SSL is not handled by putmail, but for that there is stunnel, isn’t there? (Remember the one task per program philosophy? 😉 ).

Now another great feature of putmail is the automatic way of discovering which email server to use.
Let us imagine following situation: I have three accounts, pygospa@yahoo.de, pygospa@gmx.de and pygospa@web.de . Now, if I want to differentiate between which account to use for a certain mail, all I have to do, is to create three different configuration files, such as the one above. Each of them gets the mail address as filename. So I have a configuration file named pygospa@yahoo.de with the above configuration contents.

If putmail now encounters a mail it needs to process, it first looks into the mail and searches the “FROM” header. If it is set, and if an configuration file exist, that has the same name as the “FROM” header, then that configuration file is used.

Really neat, isn’t it? I wished everything would be as easy as that *gg*

Oh, and btw., if you made a configuration file and want to test it, just create a mail:
Use any ASCII text editor (Notepad, vim, …), write a file like “test.txt” and add following into it:

FROM: pygospa@yahoo.de
TO: pygospa@web.de

Test.

And process it with putmail as follows:

pygospa@tyl ~ $ cat test.txt | putmail.py

And that is all there is!

Oh, and by the way. Here is the link to that nice tool:
http://putmail.sourceforge.net/home.html

Advertisements

Please comment. I really enjoy your thoughts!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s