Yes, you need to buy (register) a domain beforehand.
The e-mail provider of your choice that provides custom domains will ask you to
either point your domain to their nameservers (done from the domain provider’s panel)
or insert/update some DNS records on your domain (either from your domain provider’s panel if it is supported or you can link your domain to another DNS service e.g. CloudFlare)