After moving this blog on VPS, I realized my contact page isn't working anymore. It used to be that I'd receive an email everytime someone submit. Then I realized that no mailing has been setup on this server.

It used to be that my shared hosting provides SMTP server, complete with cpanel to configure my mailbox (along with everything else) and cubebox to read the mail on it.

Not that I'm on my own, I need to set it all up myself. I realized I don't need a full mailserver just to receive feedback. A local mailing system would do.

Trying out mailutils

mailutils is a set of utilities for sending mails between local users in UNIX systems. I first installed it using:

# apt install mailutils

Upon installation, I was greeted by Postfix Configuration, I think due to the mailutils having postfix as its dependency. I later found that I could have picked a less sophisticated MTA.

postfix_configuration

I simply picked "Local only", and after pressing enter, I was asked for hostname. Since the input box already had a default value of my current host, I simply pressed enter.

I had a mail sent to user from a test user of mine.

testuser$ mail -s 'Testing' user <<EOF
> line 1
> line 2
> EOF

Then as user, I checked my mail.

$ mail

"/var/mail/kenno": 1 message 1 new
>N   1 root               Fri Apr  5 21:49  15/481   Testing
? 1
. . . .
Subject: Testing
To: kenno@timkenhan.co
. . . .
From: testuser <testuser@timkenhan.co>

line 1
line 2

That's pretty much all we need. Pretty neat if you ask me.

However, as I dug deeper on the email plugin I'm using, I found that it's incompatible. That, or I just couldn't figure it out. Either way, it seems to have extensive support for sendmail.

Having sendmail instead

I first installed sendmail.

# apt install sendmail

Not as many packages got installed. That was probably from postfix's dependencies. I later found out that you could actually use sendmail as the MTA instead of postfix.

I started by having my user/config/plugins/email.yaml to:

enabled: true
to: user@timkenhan.co
from: mailer@timkenhan.co
mailer:
  engine: sendmail
  sendmail:
    bin: '/usr/sbin/sendmail -t'

Then I changed user/pages/03.contact/form.md that I already have

from this:

    . . . .
    process:
        email:
            from: "mailer@timkenhan.co"
            to:
              - "mailer@timkenhan.co"
              - ""
            subject: "[Feedback] "
            body: "

    
    
"
        save:
            fileprefix: feedback-
            dateformat: Ymd-His-u
            extension: txt
            body: "
"
    . . . .

to this:

    . . . .
    process:
        email:
            from: "mailer@timkenhan.co"
            to:
              - "user@timkenhan.co"
            subject: "[Feedback] "
            body: "
"
#        save:
#            fileprefix: feedback-
#            dateformat: Ymd-His-u
#            extension: txt
#            body: "
"
    . . . .

A few things I changed on process.email.to:

  • for some reason, "mailer@timkenhan.co" was included, not "user@timkenhan.co", therefore sending the mail to the sender and not to the receiver -- I changed it accordingly
  • "" was removed as I don't find a need to send email to the sender; I don't have the right setup to send proper email anyway as I don't have SMTP setup

I also changed process.email.body to have the txt version of twig template for submission data. I'll be using a text-based mail client, so HTML would be undesireable.

Last but not least, I commented out the entirety of process.save since I don't need the submission data saved to separate files (the mailbox would do).

Adding Captcha

While at it on the contact form, I decided to add something I've been wanting to add for a while which is Captcha.

It brought me to joy when I learned I don't need Google's ReCaptcha to achieve this, as it would save me some hassle. I think it was added some time after I was done setting up my blog; otherwise I would've known.

It's a simple six-characters Captcha, no dependency to be installed. It's probably not perfect, but for me it's enough.

On user/pages/03.contact/form.md, I added:

    fields:
        . . . .
        basic-captcha:
          label: Are you human?
          type: basic-captcha
          placeholder: copy the 6 characters
          recaptcha_not_validated: 'Captcha not valid!'

        . . . .
    process:
        basic-captcha:
            message: Humanity verification failed, please try again...
        . . . .

Reading The Mail

To read the mail, I use mutt, a command-line mail client.

mutt_main

mutt_entry

I didn't have the screenshot from before I added the Captcha, but everything else pretty much looks the same.

I probably could've gotten rid of the captcha field from the sent mail, but I'm too lazy, and it is not annoying enough. So I left it as is.