You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.4 KiB

<p>You may use this web form to contact us. Your message will be encrypted. A copy of your message will not be sent to you unless we reply. For an encrypted reply, paste or link your public key. </p>
<noscript><p>Uh-oh, you don't have javascript. This form won't work without it. Please send an email instead.</p></noscript>
<p><input type="text" id="name-input" placeholder="Your name"></p>
<p><input type="email" id="email-input" placeholder="Your email"></p>
<p><input type="text" id="subject-input" placeholder="Subject"></p>
<p><textarea id="message-input" placeholder="Your message"></textarea></p>
<p><button id="send-button">Send</button></p>
<script src="/PATH/TO/LOCAL/COPY/OF/openpgp.min.js"></script>
<script>/* global openpgp fetch */
let send = document.getElementById('send-button')
let name = document.getElementById('name-input')
let email = document.getElementById('email-input')
let subj = document.getElementById('subject-input')
let text = document.getElementById('message-input')
const API_URL = "https://mailapi.mydomain.tld/"
async function sendClicked () {
send.disabled = true
send.innerHTML = `Sending... `
let res; try {
res = await fetch(API_URL, {
method: 'POST',
// cache: 'no-cache',
headers: {'content-type': 'application/json'},
body: JSON.stringify({
name: name.value,
subj: subj.value,
email: email.value,
msg: await openpgp.encrypt({
message: await openpgp.createMessage(
{ text: `${text.value}\n` }
encryptionKeys: await openpgp.readKey({
armoredKey: `-----BEGIN PGP PUBLIC KEY BLOCK-----
} catch (err) {
send.disabled = false
alert('Failed to connect to the network. Are you online?')
send.disabled = false
if (res.status===200) {
text.value = ''; subj.value = ''; name.value = ''; email.value = ''
} else if (res.status===500)
alert('Backend failed! Please try again. If the problem persists, please email hostmaster@[this domain].')
else alert('Unknown error! Please try again. If the problem persists, please email hostmaster@[this domain].')