skip to Main Content

After creating a WordPress template using Lightsail, no email can be sent from the site.

2

Answers


  1. Chosen as BEST ANSWER

    There are few reasons and you need to solve all of them before an email can be sent from AWS Lightsail Wordpress template.

    1. By default, AWS blocks the port for sending email from EC2 instance (Lightsail is an EC2 instance behind the scene). Solution: Submit a ticket to AWS and ask them to unblock the email restriction on the server
    2. The sendmail package is NOT installed in the Lightsail Wordpress template by default. Solution: sudo apt-get install sendmail to install sendmail. After this step, you can see sendmail in /usr/sbin
    3. Sending email to a specific domain like [email protected] may result in “stat=User unknown“ error shown in /var/log/mail.log. Reason: your domain name matches either your server’s hostname or a setting in sendmail’s config file. Solution: Configure sendmail to force send emails to your actual mail server instead of itself by editing /etc/mail/sendmail.mc and add the following lines:
    define(`MAIL_HUB', `domain.com.')dnl
    define(`LOCAL_RELAY', `domain.com.')dnl
    

    Make sure to (1) change your own domain name (2) ended with the trailing dot! Reference and credit to: https://tecadmin.net/sendmail-user-unknown-error-resolved/

    1. sudo sendmailconfig to configure sendmail with the updated setting and press ‘Y’ for all default when prompted
    2. Update /opt/bitnami/php/etc/php.ini by enabling sendmail_path: env -i /usr/sbin/sendmail -t -i. Remember to remove the prefix ";" in the beginning of the line.
    3. Make sure the host name is list in in the host file /etc/hosts, e.g. 127.0.0.1 localhost myhostname
    4. Restart server sudo /opt/bitnami/ctlscript.sh restart
    5. Restart php-fpm service sudo /opt/bitnami/ctlscript.sh restart php-fpm

  2. If you’ve used the WordPress-specific package in Lightsail to create your site, you should be able to send email just by adding in an SMTP plugin and connecting it to either a transactional email service like SendGrid or Postmark, or connecting it to an existing SMTP server via username and password.

    In my experience, I’ve not found it necessary to open up ports or anything server-level when using the WordPress Lightsail image.

    For the plugin, personally, I love FluentSMTP for this as it makes things simple, gives you lots of features, and it’s free 😉

    https://fluentsmtp.com/

    The route I usually go is then to create a free SendGrid account, add your sending domain to it, and then you have to verify it by adding a few records to your DNS zone for the domain.

    https://docs.sendgrid.com/ui/account-and-settings/how-to-set-up-domain-authentication

    Once all that’s complete, generate an API key from SendGrid and enter it into FluentSMTP’s settings:

    https://fluentsmtp.com/docs/set-up-the-sendgrid-driver-in-fluent-smtp/

    Should be good to go at that point!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search