For security reasons, the Wordpress image is not set up to send emails. Even if you enable SMTP traffic on the server, you will not be able to send emails. There are 2 options to resolve this: install sendmail or configure an external SMTP plugin. The recommended option is to use an external SMTP plugin, as emails sent this way are less likely to end up in the spam folder. In this article, we will show you how to resolve this using the 2 methods.
Configure an external SMTP plugin
In this example, we will use Easy WP SMTP. You can use any external SMTP plugin; we like Easy WP SMTP because it has debugging functionality. The first thing we will do is install and configure the plugin. Here is an example of a TLS configuration:
Another example with an SSL configuration:
We can check that everything works by sending a test email from the "Test Email" tab.
Configure an external SMTP plugin with Gmail
To use Gmail for SMTP, we recommend installing the WP Mail SMTP plugin, which is already set up to use Gmail. We will need to follow the configuration steps. Once SMTP is configured, we can send emails:
Install sendmail
Before proceeding to install sendmail, the first thing we will do is set the server's hostname to a host that points to the server's IP. To do this, we will edit /etc/hosts and leave it as follows:
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
127.0.1.1 midominio.es
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhostsFinally, we will edit the /etc/hostname file and leave it as follows:
midominio.esNow we can proceed to install sendmail:
# apt install sendmailNow that we have sendmail, our WordPress will be able to send email without external plugins. Keep in mind that emails will be sent with the sender address: www-data@midominio.es.