https://github.com/rafaeljusto/contactme
Microservice for sending e-mails via HTTP interface
https://github.com/rafaeljusto/contactme
Last synced: 2 months ago
JSON representation
Microservice for sending e-mails via HTTP interface
- Host: GitHub
- URL: https://github.com/rafaeljusto/contactme
- Owner: rafaeljusto
- License: mit
- Created: 2015-05-06T11:01:46.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-08T12:29:49.000Z (about 10 years ago)
- Last Synced: 2025-03-29T06:11:26.015Z (3 months ago)
- Language: Go
- Size: 254 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog
- License: LICENSE
Awesome Lists containing this project
README
# ContactMe
Easy way to send an e-mail for your "contact me" web form.
## Features
* Remove undesireble characters (avoid script attacks)
* Validate client e-mail format
* Limit the number of e-mails from a client in a specific period
* E-mail encoded in base64
* Allow plain authentication with mail server
* Errors and warnings are logged in "/var/log/contactme.log" with fallback for standard output## API
Expect a POST request containing the fields:
| Field | Description |
| ----- | ----------- |
| name | Client name |
| email | Client e-mail to return the contact |
| subject | Subject of the client |
| message | Message of the client |## Rate Limit
* Use the [token bucket](http://en.wikipedia.org/wiki/Token_bucket) strategy
* Rate limit per IP fixed in 5 e-mails per day (burst)
* Cleanup for entries older than a day (goroutine running every 5 minutes)## HTTP status
| Status | Description |
| ------ | ----------- |
| 200 | E-mail sent |
| 400 | Invalid client e-mail format |
| 405 | Only POST requests are allowed |
| 427 | Client already sent too many e-mails |
| 500 | Something went wrong in server-side |## Use it
This service has the following parameters to run:
| Parameter | Environment Varible | Description |
| --------- | ------------------- | ----------- |
| config | CONTACTME_CONFIG | Configuration file (other params have priority) |
| port | CONTACTME_PORT | Port to listen to (default: 80) |
| mailserver | CONTACTME_MAILSERVER | E-mail server address with port (e.g. smtp.gmail.com:587) |
| username | CONTACTME_PASSWORD | E-mail server authentication password (default: same of mailbox) |
| mailbox | CONTACTME_MAILBOX | E-mail address that will receive all the e-mails |It is recommended before running the service to set the environment variables instead of using the
command line parameters for safety reasons (you don't want your password visible in the process
list), or use the configuration file.Command line example (without using environment variables):
```
# contactme -s smtp.gmail.com:587 -p "crazypassword" -m [email protected]
```To use the service with [Upstart](http://en.wikipedia.org/wiki/Upstart) you can generate the Debian
package with the script "gendeb.sh" (depends on [fpm](https://github.com/jordansissel/fpm)), install
it in your server, and fill the file "/etc/contactme/contactme.yaml" with your data.```
# ./gendeb.sh 1.0 1
# dpkg -i contactme_1.0-1_amd64.deb
# service contactme start
```## E-mail template
```
Client:
--------------------------------------------------------------------------
E-mail sent via ContactMe.
http://github.com/rafaeljusto/contactme
```## Client example
```html
input {
display: block;
margin-bottom: 20px;
}input[type=submit] {
margin: 20px auto 0px auto;
}label {
display: block;
}
Contact MeName
Subject
Message
$(function() {
$("#contactme").submit(function(e) {
e.preventDefault();var data = $(this).serialize();
$.post("http://localhost", data)
.done(function() {
alert("E-mail sent!");
})
.fail(function() {
alert("Error!");
});
});
});
```