---
id: Etc Mail-server
aliases: []
tags: []
---

- [ ] ***
  id: Etc Mail-server
  aliases: []
  tags: []

---

```bash
mysql -u mailuser -p mailserver
```

```sql
-- Add work subdomain if needed (optional)
INSERT INTO virtual_domains (name) VALUES ('liphlink.xyz');

-- Get domain IDs
SELECT id, name FROM virtual_domains;

-- Add aliases (replace domain_id with correct IDs)
-- Alias: work@liphlink.xyz -> phil@liphlink.xyz
INSERT INTO virtual_aliases (domain_id, source, destination)
VALUES (1, 'p.waibel@liphlink.xyz', 'phil@liphlink.xyz');

-- Alias: phil@work.liphlink.xyz -> phil@liphlink.xyz
INSERT INTO virtual_aliases (domain_id, source, destination)
VALUES (2, 'phil@work.liphlink.xyz', 'phil@liphlink.xyz');

-- Verify
SELECT * FROM virtual_aliases;
EXIT;
```

## example setup for multiple users, aliases and mailboxes

```sql
-- Connect to database
USE mailserver;

-- 1. Create the actual mailboxes (real users)
INSERT INTO virtual_users (domain_id, email, password) VALUES
(4, 'phil@liphlink.xyz', '{SHA512-CRYPT}$6$jBiwDe/FJozZFzKV$D0GFlDuY4xLt.T9OavIBkEZ.7.q6KnRhWzHXCxwDQmaI4p3wkHwZEjc1e4.KllL1xeYzKARdDrqWl0ScHli05/'),  -- Person 1's mailbox
(4, 'spam@liphlink.xyz', '{SHA512-CRYPT}$6$S8UOlG0ImhGWLwy5$evkDoMMh8NYGrQljiEV7iM6.0vBkMpq4Q/7ybpGW182w7aRtaFFWMnP9VYD1.PMuJosVEBDbE0SsC0xwR44851'),  -- Person 1's spam mailbox
(4, 'home@liphlink.xyz', '{SHA512-CRYPT}$6$wD6/BL3lrikvipl4$TE6STLy6oOs3t2fAwAjfEPwB1gLhYrJbC08ZLUlz/qbikscnA3ssexDEzUjLIBHYP/SAYIg5B2RpMhYEdG0Ru/'),  -- Person 1 & 2's shared mailbox
(4, 'miri@liphlink.xyz', '{SHA512-CRYPT}$6$ofVB6CU..zVerp/c$TTFn6YAt1zBHK4FMyUb2FWMqQMQAVuXPxOZzds6HlfHLCh1jbbDmDsE0MU7iNvSsoopV2OwNQTCCLXIQOUUld.'),  -- Person 2's mailbox
(4, 'coaching@liphlink.xyz', '{SHA512-CRYPT}$6$wp.Bxin7aZjsJDwZ$OKzgR2Vu8puw7xUKvjHzqZgCgj0rfbjBzbdZcu8hxtRo0q9aHxUaL9.tYMGHGOMzELCteIMOo8oicg4EbpZ2E1');  -- Person 2's work mailbox

-- 2. Person 1's aliases (both forward to person1@liphlink.xyz)
INSERT INTO virtual_aliases (domain_id, source, destination) VALUES
(4, 'p.waibel@liphlink.xyz', 'phil@liphlink.xyz'),
(4, 'philipp.waibel@liphlink.xyz', 'phil@liphlink.xyz'),
(4, 'pw@liphlink.xyz', 'phil@liphlink.xyz');

-- 2. Person 1's spam adress (both forward to person1@liphlink.xyz)
INSERT INTO virtual_aliases (domain_id, source, destination) VALUES
(4, 'blue@liphlink.xyz', 'spam@liphlink.xyz'),
(4, 'red@liphlink.xyz', 'spam@liphlink.xyz');

-- 4. Person 2's aliases (all three forward to person2@liphlink.xyz)
INSERT INTO virtual_aliases (domain_id, source, destination) VALUES
(4, 'mh@liphlink.xyz', 'miri@liphlink.xyz'),
(4, 'miriam.herten@liphlink.xyz', 'miri@liphlink.xyz'),
(4, 'miriam@liphlink.xyz', 'miri@liphlink.xyz');

-- 2. Person 1's spam adress (both forward to person1@liphlink.xyz)
INSERT INTO virtual_aliases (domain_id, source, destination) VALUES
(4, 'zelgi@liphlink.xyz', 'home@liphlink.xyz');

INSERT INTO virtual_aliases (domain_id, source, destination) VALUES
(4, 'embodiment@liphlink.xyz', 'coaching@liphlink.xyz'),
(4, 'contact@liphlink.xyz', 'coaching@liphlink.xyz');

-- Forward to multiple recipients
INSERT INTO virtual_aliases (domain_id, source, destination)
VALUES (1, 'team@liphlink.xyz', 'phil@liphlink.xyz,alice@liphlink.xyz');

-- View everything
SELECT
    'USERS' as type,
    id,
    email as address,
    'MAILBOX' as note
FROM virtual_users
WHERE domain_id = 1
UNION ALL
SELECT
    'ALIASES' as type,
    id,
    CONCAT(source, ' → ', destination) as address,
    'FORWARDS TO' as note
FROM virtual_aliases
WHERE domain_id = 1
ORDER BY type, address;
```

## Create Tables

```sql
-- Domains table
CREATE TABLE IF NOT EXISTS virtual_domains (
    id INT NOT NULL AUTO_INCREMENT,
    name VARCHAR(50) NOT NULL,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Users table
CREATE TABLE IF NOT EXISTS virtual_users (
    id INT NOT NULL AUTO_INCREMENT,
    domain_id INT NOT NULL,
    password VARCHAR(200) NOT NULL,
    email VARCHAR(120) NOT NULL,
    PRIMARY KEY (id),
    UNIQUE KEY email (email),
    FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Aliases table
CREATE TABLE IF NOT EXISTS virtual_aliases (
    id INT NOT NULL AUTO_INCREMENT,
    domain_id INT NOT NULL,
    source VARCHAR(100) NOT NULL,
    destination VARCHAR(100) NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

## Show table contents

```sql
-- Show all domains
SELECT * FROM virtual_domains;

-- Show all users
SELECT * From virtual_users;

-- Show all aliases
SELECT * From virtual_aliases;
```

## Passwords for mailboxes

```
phil@liphlink.xyz: Fqi5UAyr46e69fG
spam@liphlink.xyz: ANZ6JJPBiB7k1c7k
miri@liphlink.xyz: HORsyzL7jV7jQzP
home@liphlink.xyz: zjlWmau4u7b19MS
coaching@liphlink.xyz: roUHvaetocCWFmgY
```

# Create password files
mkdir -p ~/.mail-passwords
echo "Fqi5UAyr46e69fG" > ~/.mail-passwords/phil
echo "ANZ6JJPBiB7k1c7k" > ~/.mail-passwords/spam
chmod 600 ~/.mail-passwords/*

# Update .mbsyncrc
sed -i 's|PassCmd "pass show mail/phil@liphlink.xyz"|PassCmd "cat ~/.mail-passwords/phil"|g' ~/.mbsyncrc
sed -i 's|PassCmd "pass show mail/spam@liphlink.xyz"|PassCmd "cat ~/.mail-passwords/spam"|g' ~/.mbsyncrc

# Test IMAP connection manually
openssl s_client -connect mail.liphlink.xyz:993 -quiet

# Then type (use your password):
a LOGIN phil@liphlink.xyz Fqi5UAyr46e69fG
b SELECT INBOX
c FETCH 1:5 (FLAGS SUBJECT)
d LOGOUT