contact-mailer/readme.md

90 lines
3.3 KiB
Markdown
Raw Normal View History

2020-05-01 06:12:14 +00:00
# Contact Mailer
A minimal python app to send mail when people fills in your contact form!
## Why?
Here at Jean-Cloud, we are fans of static websites. They are easily distributed, use few ressources and are very secured.
But the first limitation is… No interractions… So no contact form… That would be a shame to deploy a website without a contact section!
## How does it work?
### Create the contact form
- Create or reuse an existing contact form
- Add the `action` parameter to the mailer address + `/submit`
- Get a token from this mailer app and place it in your form like :
2020-05-02 15:32:08 +00:00
2020-05-01 06:12:14 +00:00
```
<form action="https://mailer.jean-cloud.net/submit" method="POST">
<input type="mail" name="mail" />
<input type="text" name="nom" />
<input type="text" name="objet" />
<textarea name="contenu" required="required"></textarea>
<input type="hidden" name="token" value="eYEqyDXk4bKgFrwuWdN0B9UZtOnIlJcRzx8mh2jCsPTAH7V5QS" />
<input type="submit" />
</form>
```
### Identifying on the mailer
Ask for an account to the mailer admin.
They will hand you a password like : `hepaNRSkqcxKD1QujwTr9I6XyiA7VOCGnsWbMtdlZJz0o8ULHP`
### Configure the mail sending
You can choose how information sent with form will be displayed in the final mail! Actually there are two templatable fields: the mail subject and content.
Here is a template example :
```
subject: "[Contact] {{nom|anonyme}} — {{object|no object}}"
2020-05-02 17:36:46 +00:00
content: "Message de contact :%0D%0A{{message}}"
2020-05-01 06:12:14 +00:00
```
When the form will be submitted to the mailer, parts like `{{…}}` will be replaced by fields content of the same name!
If the field holds no value, two possibilities:
- The default value specified after `|` is used
- There is no default value, the form is rejected.
TIP: you can set an empty default value in order to have a facultative field: `{{name|}}`.
## Installation
### Docker
`docker pull jeancloud/contact-mailer`
### Git & Pip in virtualenv
```
git clone https://git.jean-cloud.net/adrian/contact-mailer
cd contact-mailer
virtualenv venv
. venv/bin/activate
pip install -r requirements.txt
```
## Running it
The app needs a lot of env vars to run :
```
SMTP_SERVER_ADDRESS=mail.gandi.net
SMTP_SERVER_PORT=465
SMTP_SSL=true
SMTP_SERVER_USERNAME=nepasrepondre@jean-cloud.org
SMTP_SERVER_PASSWORD=B9UZtOnIlJcRzx8mh2jCsPTQujwTr9I6XyiA
SMTP_SERVER_SENDER=nepasrepondre@jean-cloud.org
MONGODB_HOST=mongodb
ADMIN_PASSWORD=test
UID=1000
```
You can store them in a `.env` file. The python app will read it or you can pass it to the docker container with `run` option `--env-file`.
2020-05-01 14:00:49 +00:00
2020-05-02 15:32:08 +00:00
- `SMTP_*` are used to connect to the smtp server that will send the mail.
- `SMTP_SSL` is used to enable SSL
- `SMTP_STARTTLS` is used to enable STARTTLS if `SMTP_SSL` is not defined. In no ssl and starttls are defined the app wont connect.
- `MONGODB_HOST` the host to connect to mongodb
- `ADMIN_PASSWORD` password used to manage users
- `UID` used to set the uwsg socket ownership in production
2020-05-01 14:00:49 +00:00
## Roadmap
### Near future
- go on docker hub
- use a standart logger (used by bottle and uwsgi) to log error on mail fail
- [unit tests](https://bottlepy.org/docs/dev/recipes.html#unit-testing-bottle-applications)
- add redirection urls to form config
2020-05-01 14:06:59 +00:00
- Include some [capcha](https://alternativeto.net/software/recaptcha/) support
2020-05-01 16:58:19 +00:00
- Correctly escape html entities
2020-05-01 14:00:49 +00:00
### Ameliorations
- Use real user/passwords accounts
2020-05-02 15:32:08 +00:00
- Créate a gui client