With this system people can register with their email in a mailing list for the server owner later be able send any wanted email.
I built this for myself, and put it here just as an example of how a web service can be done in C. If anyone wants to use it probably you will want to edit the email templates that exist in the code.
Clone with submodules for the dependencies of each part
git clone --recurse-submodules git@github.com:drmargarido/mailing_list.git
- Allow register in a game mailing list.
- Send email to users to confirm that they joined the mailling list.
- Allow registered users to unsubscribe if they want.
NOTE: There is no endpoint to add new games to the database, it needs to be done
with the create_game
function that exists in the server/database.c
file or
with a query directly in the database.
- Create postgres database with name maling_list.
- Edit the file
server/environments/dev.c
with the postgres database user password. - Run migrations.
psql -U postgres -d mailing_list -h 127.0.0.1 -f server/migrations/001_init.sql
psql -U postgres -d mailing_list -h 127.0.0.1 -f server/migrations/002_add_confirm.sql
- Install libpq.
- Install libcurl.
- Compile with
make
. - Run the server
bin/list-server
.
- Fill the files
server/environments/prod.c
andclient/environments/prod.c
with your wanted configurations. - Compile the wanted binaries with the
make release
command. - Create the user
lists
. - Copy the server binary to the
/opt/mailing_list
folder. - Make sure the user can execute the binaries on the
/opt/mailing_list
folder. - Create the database
mailing_list
and run the following migrations.
psql -U mailing_list -d mailing_list -h 127.0.0.1 -f server/migrations/001_init.sql
psql -U mailing_list -d mailing_list -h 127.0.0.1 -f server/migrations/002_add_confirm.sql
- Create the user
mailing_list
in the database with access to themailing_list
database. - Copy the systemd service to the
/etc/systemd/system
folder. - Enable and activate the service.
- Edit the nginx configuration with the server domain and SSL certs and add it to the
/etc/nginx/sites-available
folder. - Link the file to the
/etc/nginx/sites-enabled/
folder and restart nginx. - If we don't have the ssl certificates yet let only the port 80 part in the configuration and run the certbot.
- Block the 8080 port in the firewall for external requests so the internal server is not exposed.
/sbin/iptables -A INPUT -s 127.0.0.1 -p tcp --destination-port 8080 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --destination-port 8080 -j DROP
- Copy the cron binary to the
/opt/mailing_list
folder. - Make sure the user
lists
is the owner of the cron binary. - Copy the
cron/mailing_list
file to/etc/cron.d/mailing_list
.
- For now the user for testing in the database is
postgres
with the password123qweasd.
. - Run the following command:
make test
- Consult mailing list by game.
- Send email to all users of a mailing list.
A devlog about the mailing list development can be found here.