# Social-Mail Web-Server

Social Mail Server is a simple mail and file server.

Social Media features such as Like, comment and subscribe are planned in future release.

# Self hosted
Social Mail Server is a self hosted web/mail server. You can choose to host anyway you like it. No more privacy nightmares and big forms to sign up and lots of terms and conditions. Just communicate with your audience simply through email.

# Docker Container
1. Create vars.env files with the variables from the following table.
2. Run following

```bash
docker pull neurospeech/social-mail-web-server:latest
docker volume socialmaildata
docker run --name=socialmail --env-file vars.env -p 25:25 -p 443:443 -p 80:80 -v socialmaildata:/data --restart=always -d neurospeech/social-mail-web-server:latest
docker image prune -f
docker volume prune -f
docker builder prune -a -f
```

# Custom Build
1. You will need NodeJS + ClamAV + PostgresSQl.
2. After you have installed all of the above, run following steps.
   a. `mkdir social-mail`
   b. `cd social-mail`
   c. `npm init` Press enter for all defaults.
   d. `npm install -s @social-mail/social-mail-web-server`.
   e. `node --enable-source-maps ./node_modules/@social-mail/social-mail-web-server/index.js`

# Upcoming Social Features
Social Mail Server will adds few tricks to send/receive social messages through emails. The best part is, you will be able to communicate with everyone even if
they are not on same mail server. You can basically communicate/socialize with your friends and family without having to go through big tech.

# Environment Variables
| Environment Variable               |Required | Defaults     |                             |
|------------------------------------|---------|--------------|-----------------------------|
| SOCIAL_MAIL_HOST                   |Yes      |              |                             |
| SOCIAL_MAIL_PATH                   |         | /            | Root path for all API       |
| SOCIAL_MAIL_HOSTED_EMAIL_DOMAIN    |         |              | For sending Email notifications          |
| SOCIAL_MAIL_ALT_HOSTS              |         |              |                             |
| SOCIAL_MAIL_NAME                   |         | Social Mail  | PWA Name                    |
| SOCIAL_MAIL_CDN                    |         |              |                             |
| SOCIAL_MAIL_ADMIN_PASSWORD         |Yes      | social-admin | This will be set only first time |
| SOCIAL_MAIL_SECRET_KEY             |Yes      |              | Used to encrypt secrets     |
| SOCIAL_MAIL_AV                     |         | ClamAV       | Anti Virus Scanner          |
| SOCIAL_MAIL_AV_PORT                |         | ClamAVDef    | Anti Virus Scanner Port     |
| SOCIAL_MAIL_AV_DEBUG               |         | false        | true to enable debug mode   |
| SOCIAL_MAIL_SMTP_PORT              |         | 25           | 0 to disable                |
| SOCIAL_MAIL_SSL_MODE               |         | lets-encrypt | none,lets-encrypt,self-signed |
| SOCIAL_MAIL_SSL_PORT               |         | 443          | SSL Port, 0 to disable      |
| SOCIAL_MAIL_SSL_HOSTS              |         |              | Additional SSL Hosts, all must point to same IP address.      |
| SOCIAL_MAIL_SSL_LE_EMAIL           |[Yes]    |              | Email for Lets Encrypt      |
| SOCIAL_MAIL_SSL_LE                 |         | staging      | Change to production        |
| SOCIAL_MAIL_SSL_ACME_EP            |         |              | Zero SSL End Point for ACME |
| SOCIAL_MAIL_SSL_ACME_EAB_KID       |         |              | Key ID                      |
| SOCIAL_MAIL_SSL_ACME_EAB_HMAC      |         |              | HMAC                        |
| SOCIAL_MAIL_SSL_PATH               |         | /data/cert   | Certificates folder         |
| SOCIAL_MAIL_TMP_PATH               |         | /tmp         | Temporary files             |
| SOCIAL_MAIL_TMP_SIZE               |         | 7gb          | Temporary Storage Size      |
| SOCIAL_MAIL_STORAGE                |Yes      | s3           | s3,volume,azure,db          |
| SOCIAL_MAIL_STORAGE_PATH           |         |              | Volume Path                 |
| SOCIAL_MAIL_AZURE_BLOB_CONN_STRING |[Yes]    |              | Blob Connection String      |
| SOCIAL_MAIL_AZURE_BLOB_CONTAINER   |[Yes]    |              | Blob Container (Must Exist) |
| SOCIAL_MAIL_S3_END_POINT           |Yes      |              |                             |
| SOCIAL_MAIL_S3_BUCKET              |Yes      |              |                             |
| SOCIAL_MAIL_S3_ACCESS_KEY          |         |              |                             |
| SOCIAL_MAIL_S3_SECRET              |         |              |                             |
| SOCIAL_MAIL_DB_SERVER              |         | postgres     | postgres                    |
| SOCIAL_MAIL_DB_HOST                |         | localhost    |                             |
| SOCIAL_MAIL_DB_PORT                |         | 5432         |                             |
| SOCIAL_MAIL_DB_DATABASE            |         | SocialMails  |                             |
| SOCIAL_MAIL_DB_USER                |         | postgres     |                             |
| SOCIAL_MAIL_DB_PASSWORD            |         | postgres     |                             |
| SOCIAL_MAIL_DB_SSL                 |         | true         | Set false for local/testing |
| SOCIAL_MAIL_AUTH_COOKIE            |         | sm-a1        | Name of HTTP Cookie         |
| SOCIAL_MAIL_AUTH_COOKIE_SECURE     |         | true         | Enable HTTPS only Cookie    |
| SOCIAL_MAIL_BACKUP                 |         |              | s3, azure                   |
| SOCIAL_MAIL_BACKUP_S3_BUCKET       |         |              |                             |
| SOCIAL_MAIL_LINKS_HOME             |         | /            | External home link          |
| SOCIAL_MAIL_LINKS_LOGIN            |         |              | External login link         |


# Hosting Modes
1. Self Hosted Cluster with Lets Encrypt

# Why not pm2?
1. Not needed, difficult to setup ACME certificates.
2. pm2 doesn't offer anything more than what inbuilt cluster is offering.

# Indexing Variance

1. Table with status columns such as 'sent', 'received' etc.. does not need tokenization as the index size difference is less than 1% due to less number of different values.
2. Table with email address would certainly benefit from tokenization as the storage itself would need number of bytes for single row as well as the index size would be significantly smaller. e.g.

MailboxContactEmails table with Rows 486917 has following size differences.
Size Without Tokenization PK 37MB, Index 31MB, Total 68MB
Size With Tokenization PK 19MB, Index 16MB, Total 32MB

So Tokenization has more than 50% Improvement.

Reason behind this improvement is size of email address itself, most email addresses would require on an average 30 bytes, where else tokenized bigint would only need 8 bytes.

In short, if the column contains very few different values, tokenization is not helpful. But if the column can contain randome values, the tokenization would reduce the size and increase performance by more than 50% easily.