Build your own sendgrid

Kushagra KumarKushagra Kumar
2 min read

In this post I will talk about how we can create our own mail server, use SMTP and send mails every day.

I will also talk about some good mail practices which you can follow to reduce spam score and increase your domain reputation

Let’s start

I will assume you know how to create your account on digitalocean. Why digitalocean? because it allows us to use Port 25, this won’t work on AWS EC2 or any other cloud providers, you will have to request them to give permission for Port 25. You can also use hetzner they are amazing.

  1. Create a droplet - Ubuntu - 4$ plan

  2. Connect to the console, once the droplet is created

    1.   sudo apt update && sudo apt upgrade
      

      Update and upgrade - good practice as always

    2. Find your ip public address

    3. Go to cloudflare or wherever you are hosting your domain

    4. Add 2 a records

      1. mail.yourdomain.com - Your ipv4

      2. yourdomain.com - Your ipv4

    5. Go back to your server

    6.   curl -LO lukesmith.xyz/emailwiz.sh
      

      Paste this command

    7.   sudo chmod +x emailwiz.sh
      

      Change the permission

    8. ./emailwiz.sh
      

      Run the script

    9. Choose Internet site

    10. Put your domain - yourdomain.com

    11. You will get this error

  1. Open emailwiz.sh - Use vim if you know how to quit vim

  2. Comment out these 2 lines - use # to comment

  3. Run the script again - ./emailwiz.sh

  4. You will get some dns records which you need to add in your domain

  5. Once done. Let’s create some users

  6. useradd -m -G mail kush
    passwd kush
    

    Add user kush

  7. Now let’s test if everything is working

  8. Go to https://smtpserver.com/smtptest

  9. Add SMTP hostname as mail.yourdomain.com - username - kush, pass - kush, Port 465

  10. Mail from kush@mail.yourdomain.com

  11. Mail to whateveryouwant-whatever.com

  12. If you are not getting mail, check error log using journalctl -xe

  13. If you are getting issue like these, mostly your 25 port is not open

    1. Connection timeout

    2. Connection failed

Some ways you can improve your spam score

Go to https://www.mail-tester.com/ send an email and check

  1. Make sure your domain is not new

  2. Digitalocean mails will mostly go to spam

0
Subscribe to my newsletter

Read articles from Kushagra Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kushagra Kumar
Kushagra Kumar