KB68 Implement newsletter sending.

Change-Id: I1d56e40d7f35d6be77fde1a1e8519a91bd2dc3b8
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 3d56d21..b7c54da 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -9,6 +9,7 @@
 
 mulkcms.tag-base = hub.benkard.de
 mulkcms.posts.default-max-results = 25
+mulkcms.newsletter.time-zone = Europe/Vienna
 
 quarkus.datasource.db-kind = postgresql
 quarkus.datasource.jdbc.driver = org.postgresql.Driver
@@ -61,6 +62,13 @@
 mulkcms.jwt.issuer = https://matthias.benkard.de
 mulkcms.jwt.validity = P1D
 
+# E-mail settings
+quarkus.mailer.from = mulkcms@benkard.de
+quarkus.mailer.host = mail.benkard.de
+quarkus.mailer.port = 587
+quarkus.mailer.start-tls = REQUIRED
+quarkus.mailer.username = mulkcms@benkard.de
+
 # Deployment
 docker.registry = docker.benkard.de
 
@@ -89,6 +97,9 @@
 kubernetes.env-vars[1].name = QUARKUS_OIDC_CREDENTIALS_SECRET
 kubernetes.env-vars[1].secret = mulkcms2-secrets
 kubernetes.env-vars[1].value = keycloak-secret
+kubernetes.env-vars[2].name = QUARKUS_MAILER_PASSWORD
+kubernetes.env-vars[2].secret = mulkcms2-secrets
+kubernetes.env-vars[2].value = email-password
 kubernetes.secret-volumes[0].volume-name = secrets
 kubernetes.secret-volumes[0].secret-name = mulkcms2-secrets
 kubernetes.secret-volumes[0].default-mode = 0444
diff --git a/src/main/resources/db/changeLog-1.7.xml b/src/main/resources/db/changeLog-1.7.xml
new file mode 100644
index 0000000..8824115
--- /dev/null
+++ b/src/main/resources/db/changeLog-1.7.xml
@@ -0,0 +1,55 @@
+<?xml version="1.1" encoding="UTF-8" standalone="no"?>
+<databaseChangeLog
+  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="
+    http://www.liquibase.org/xml/ns/dbchangelog
+    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.10.xsd">
+
+  <changeSet author="mulk" id="1.7-1">
+    <createTable tableName="newsletters" schemaName="benki">
+      <column name="id" type="INTEGER">
+        <constraints primaryKeyName="newsletters_pkey" nullable="false" primaryKey="true"/>
+      </column>
+
+      <column name="date" type="TIMESTAMP WITH TIME ZONE">
+        <constraints nullable="false"/>
+      </column>
+    </createTable>
+
+    <addColumn tableName="bookmarks" schemaName="benki">
+      <column name="newsletter" type="INTEGER">
+        <constraints foreignKeyName="bookmarks_newsletter_fkey" references="benki.newsletters(id)"/>
+      </column>
+    </addColumn>
+
+    <addColumn tableName="lazychat_messages" schemaName="benki">
+      <column name="newsletter" type="INTEGER">
+        <constraints foreignKeyName="lazychat_messages_newsletter_fkey" references="benki.newsletters(id)"/>
+      </column>
+    </addColumn>
+
+    <addColumn tableName="posts" schemaName="benki">
+      <column name="newsletter" type="INTEGER">
+        <constraints foreignKeyName="posts_newsletter_fkey" references="benki.newsletters(id)"/>
+      </column>
+    </addColumn>
+  </changeSet>
+
+  <changeSet author="mulk" id="1.7-2">
+    <createTable tableName="newsletter_subscriptions" schemaName="benki">
+      <column name="id" type="SERIAL" autoIncrement="true">
+        <constraints primaryKeyName="newsletter_subscriptions_pkey" nullable="false" primaryKey="true"/>
+      </column>
+
+      <column name="start_date" type="TIMESTAMP WITH TIME ZONE" defaultValue="now()">
+        <constraints nullable="false"/>
+      </column>
+
+      <column name="email" type="VARCHAR">
+        <constraints nullable="false" unique="true" uniqueConstraintName="newsletter_subscriptions_email_key"/>
+      </column>
+    </createTable>
+  </changeSet>
+
+</databaseChangeLog>
diff --git a/src/main/resources/db/changeLog.xml b/src/main/resources/db/changeLog.xml
index f1c0849..7b4b700 100644
--- a/src/main/resources/db/changeLog.xml
+++ b/src/main/resources/db/changeLog.xml
@@ -13,5 +13,6 @@
   <include file="db/changeLog-1.4.xml"/>
   <include file="db/changeLog-1.5.xml"/>
   <include file="db/changeLog-1.6.xml"/>
+  <include file="db/changeLog-1.7.xml"/>
 
 </databaseChangeLog>
diff --git a/src/main/resources/templates/NewsletterSender/newsletter.txt b/src/main/resources/templates/NewsletterSender/newsletter.txt
new file mode 100644
index 0000000..1c4228f
--- /dev/null
+++ b/src/main/resources/templates/NewsletterSender/newsletter.txt
@@ -0,0 +1,38 @@
+{@int newsletterNumber}
+{@java.time.LocalDate date}
+{@java.util.List<eu.mulk.mulkcms2.benki.bookmarks.Bookmark> bookmarks}
+{@java.util.List<eu.mulk.mulkcms2.benki.lazychat.LazychatMessage> lazychatMessages}
+{@java.lang.String unsubscribeUri}
+New Blog Posts
+==============
+
+{#for post in lazychatMessages}
+* {post.date.humanDate}  <https://matthias.benkard.de/posts/{post.id}>
+{post.text.content}
+
+
+{/for}
+
+
+New Bookmarks
+=============
+
+{#for post in bookmarks}
+* {post.date.humanDate}  <https://matthias.benkard.de/posts/{post.id}>
+* {post.title}
+* <{post.uri}>
+
+{post.text.description}
+
+
+{/for}
+
+
+
+Your Subscription
+=================
+
+You are receiving this email because you are subscribed to the MulkCMS
+newsletter.  To unsubscribe, send an email to:
+
+  <mulkcms+unsubscribe@benkard.de>