Skip to content
Yaroslav edited this page Feb 13, 2016 · 5 revisions

sendmail.py

sendmail.py is a sendmail-like application for testing purposes with pipelining messages processing for Linux developed in Python 3.

sendmail.py developed for usage in the Debian based Linux distributions.

You can use it as "fake sendmail" for PHP web sites.

Successfullty tested in the following OS:

  1. Xubuntu 14.04 LTS "Trusty Tahr".
  2. Elementary OS Freya.

Features

Application provides two scripts:

  1. sendmail.py - reads email messages from standard input and then process it according to your settings using one of available processors:
  2. FilesystemProcessor - saves messages to files in the specified directory.
  3. NotifyProcessor - displays desktop notifications when message sent. Does not works if sendmail.py used in the Apache2 environment; in this case watch.py need to be used.
  4. SmtpProcessor - sends messages using SMTP server.
  5. MandrillProcessor - sends messages using Mandrill API (you need to create Mandrill API key).
  6. watch.py - watches filesystems and displays desktop notifications when new message file created. Active Watcher displays icon in the system tray area.

Installation

Dependencies

  • python3-notify2
  • python3-pyinotify

Install dependencies in Ubuntu:

sudo apt-get install \
  python3-notify2 \
  python3-pyinotify

Install sendmail.py

Possible installation methods:

  1. Clone git repository.
  2. Download Zip Archive.

Clone repository

git clone https://github.com/chupikov/sendmail.py.git /home/user/bin/sendmail.py

Create configuration file

cp /home/user/bin/sendmail.py/config-sample.json /home/user/bin/sendmail.py/config.json

Configuration

Create configuration file for PHP

WARNING! When you use sendmail.py from Apache NotifyProcessor will not works - in this case you have to use Watcher application.

Create separate file (for example /home/user/bin/sendmail.py/config-php-apache2.json).

[
  {
    "name": "FileSystem: /var/mail/sendmail/new",
    "class": "FilesystemProcessor",
    "enabled": true,
    "directory": "/var/mail/sendmail/new",
    "num_file": "/var/mail/sendmail/num",
    "extension": ".eml",
    "number": 1,
    "name_length": 6
  },
  {
    "name": "SMTP Server",
    "class": "SmtpProcessor",
    "enabled": true,
    "username": "yourmail@yourdomain.com",
    "password": "YOUR_PASSWORD",
    "host": "SMTP_SERVER_ADDRESS",
    "port": 25,
    "to_address": "yourmail@yourdomain.com",
    "from_address": "yourmail@yourdomain.com",
    "starttls": true
  }
]

Create directories for FilesystemProcessor

Create directory defined in the directory section of the configuration file and allow write to all:

sudo mkdir /var/mail/sendmail
sudo mkdir /var/mail/sendmail/new
sudo chmod -R 777 /var/mail/sendmail

Configure PHP

In the Ubuntu PHP configuration file for Apache located in /etc/php5/apache2/php.ini.

Open file /etc/php5/apache2/php.ini and edit sendmail_path option:

sendmail_path = /home/user/bin/sendmail.py/sendmail.py -c /home/user/bin/sendmail.py/php-apache2.json

Restart Apache:

sudo service apache2 restart

Run Watcher

After configuration you can use Watcher application in purposes of receive desktop notification messages about emails sent from Apache.

/home/user/bin/sendmail.py/watch.py -c /home/user/bin/sendmail.py/php-apache2.json