How to send e-mail without creating an e-mail account?

Pritthish Nath
3 min readMay 12, 2021

--

Prerequisites

  • A Linux VPS with a public IP.
  • A public domain.

Considering you have installed the package sendmail ,

sudo apt install sendmail

This tutorial will guide you on how to configure it. It is made the way you can simply copy and paste the necessary commands and settings.

Configuring hosts

First, you have to set the hosts and hostname files with your domain name.

sudo nano /etc/hosts

Add your domain before localhost or in a new line before it.

127.0.0.1   example.com localhost

Then, add your domain example.com in local-host-names file,

sudo nano /etc/mail/local-host-names

Adding SPF on domain’s DNS

SPF allows senders to define which IP addresses or domains are allowed to send mail on behalf of a particular domain.

Assuming your static IP is 20.21.22.23 , you have to add a TXT Record in your domain’s DNS zone.

Type: TXT
Name/host: @
Value: v=spf1 ip4:20.21.22.23 ~all
TTL: 300 (if there any)

If you have hosted your email server on different place you have to add that server IP or domain in the same statement. Adding Multiple SPF records will not work. To add multiple outgoing mail server from the domain add as the following,

v=spf1 ip4:20.21.22.23 ip4:30.31.32.33 ~all***OR with domain name for third party server***v=spf1 ip4:20.21.22.23 include:zoho.in ~all

You can verify your record after adding here.

Configuring OpenDKIM

DKIM provides an encryption key and digital signature that verifies that an email message was not faked or altered.

OpenDKIM is an open source implementation of the DKIM sender authentication system.

Install opendkim,

sudo apt-get install opendkim opendkim-tools

DKIM uses a private and public key pair for signing, the public key is stored in a TXT record in the DNS zone, similar to SPF.

opendkim-genkey -t -s default -d example.com

Here the -s option defines the selector name which will be added in DNS zone. This command generates two files in the current directory based on the selector’s name, e.g. default.txt and default.private .

Now create a new folder in /etc and copy the the private key file default.private there,

sudo mkdir /etc/opendkim
sudo cp default.private /etc/opendkim/

Now, update the /etc/opendkim.conf file,

sudo nano /etc/opendkim.conf

Update the four following lines with appropriate value,

Domain          example.com
KeyFile /etc/opendkim/default.private
Selector default

Socket inet:8891@localhost

Start the service,

sudo service opendkim start

Adding DKIM on domain’s DNS

Now extract the DKIM information from the default.txt file, which store the public key and add as a TXT record to your DNS zone. The name should be ._domainkey prefixing your selector name.

Please note, no quotation or space should be in the value of p= and cut the t=y before from it, e.g.

Type: TXT
Name/host: default._domainkey
Value: v=DKIM1; h=sha256; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDbpMiQR1EMmOmCYzzuHYlXho97NnX1/nFCftJLjY2NVkGlCdxMpI3oGeM1DmzdbC9eySW+GbFnPs0FrPB5Tqod1XXYI3gwrMihIyMJfsIMAU0EPJKvJjwsELNYj4UHWBhWIjusGw0AeDQuUH0sCYOkdPkOSvM2wpZsvHkDZwIDAQAB
TTL: 300 (if there any)

Configuring Sendmail

Append the following line to /etc/mail/sendmail.mc .

Keep an eye on the ` and ' characters in the sendmail.mc file. Put them in the right places like below,

INPUT_MAIL_FILTER(`opendkim', `S=inet:8891@localhost')

Compile it to sendmail.cf as root, then restart the service,

sudo -i
cd /etc/mail
m4 sendmail.mc > sendmail.cf
service sendmail restart

The record could be verified here.

Adding DMARC on domain’s DNS

DMARC unifies the SPF and DKIM authentication mechanisms into a common framework and allows domain owners to declare how they would like email from that domain to be handled if it fails an authorization test.

To add DMARC record you will need a email address of your domain where you can receive incoming mails. Add as the following TXT record,

Type: TXT
Name/host: _dmarc
Value: v=DMARC1; p=none; pct=100 rua=mailto:email_address@example.com
TTL: 300 (if there any)

You can verify the record here.

These guide could get your emails to receiver’s inbox for now. To check create a file nano mail.html , and add the following headers and body,

From: no-reply@example.com
To: recipient@gmail.com
Subject: MIME Check
Content-Type: text/html
<html>
<body>
This is a test.
</body>
</html>

Put the same recipient address in command,

sendmail -v recipient@gmail.com < mail.html

Checkout the recipient inbox as well as spam if something went wrong view the source code of the email.

I hope this post save someone some time. Stay safe.

--

--

Pritthish Nath
Pritthish Nath

Written by Pritthish Nath

Web developer based in Kolkata

Responses (1)