Email (WordPress)

Uit De Vliegende Brigade
Versie door Jeroen Strompf (overleg | bijdragen) op 9 mei 2023 om 21:00 (→‎Settings)
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Naar navigatie springen Naar zoeken springen

Everything concerning email and WordPress in one article.

SMTP client

The wp-mail-smtp plugin from WPForms in 2019, with settings available under the general Settings link
The wp-mail-smtp plugin from WPForms in 2023, now with settings under its own menu WP Mail SMTP

By default, a WordPress site assumes that an SMTP server is active on the same server as the site itself and that it is accessible via PHP without further authentication. However, I rarely encounter this situation.

In practice, the SMTP server usually is an external server (e.g., from TransIP). In this case, an SMTP client is needed, similar to an email client like Thunderbird or Outlook and this usually happens in the form of an email client plugin, smtp client plugin or just smtp plugin.

With an email client like Thunderbird, you can send email from any email addresses, provided you have the login details. Although it's sometimes hard to imagine, it's the same with an smtp client like wp-mail-smtp: It can send email on behalf of any email account to which you have the login details (and a minor additional requirement: don't send email in the name of another email address).

wp-mail-smtp

wp-mail-smtp or WP Mail SMTP is an smtp client plugin and it is the only one that is used in this article. I don't think I ever used another smtp plugin. Additionally, I rarely use email addresses other than from TransIP, so in this article, only these are used.

Installation

wp plugin install wp-mail-smtp --activate

Configuration - Example

I don't think this chapter is very usefull - Maybe back in 2017, it was, or I just don't know the use case anymore:

  • Using TransIP email server
  • For a domain that is a subdomain of a domain that is registered with TransIP
  • Recipient & sender are the same email address
Top part of the configuration screen
Lower part of the configuration screen. This is from 2017. At that time, the SMTP password was stored in the database without encryption. I believe this has changed around 2022
Results

Settings

  • Some settings are tricky, to avoid impersonating another email address (spoofing?)
  • Example used in this section: Sites example.nl, example.uk and example.us all use the shared email address info@example.nl
  • Only the less obvious fields are discussed here.

From Email

  • This is the actual email address that is being used
  • In the example: info@example.nl for all three sites mentioned above.

Force From Email

I think I never used this setting.

From Name

  • Fill in the name that you want to appear in email clients along the email address
  • In the example: The name of the actual domain: example.nl, example.uk and example.us respectively
  • Do use this field! Otherwise recipients see an email address that they don't know, rather than a name that they hopefully do know.

Force From Name

I think I never used this setting. Or maybe I did, and it caused problems or made the email from field look ugly.

Return Path

I think I never used this.

Mailer

TransIP? → Other SMTP.

SMTP Username

The login for the email account. For the example: Always info@example.nl.

Email Test

The test functionality works very well. I especially like it, that it remembers the recipient's email address. It's a minor detail but it makes life just a bit more enjoyable that it already is

Site & email addresses

Where do you have to configure what, concerning email on a site? This is mostly about WooCommerce webshops that I manage on behalf of customers.

KBO Options

This is a custom component with all kinds of useful settings. Only in use for this specific customer, of course.

Administration Email

  • Settings » General » Administration Email Address
  • I use my own business email address here. It's no problem if I also have a user account on the same site, with the same email address.

WP Mail SMTP

  • Settings » WP Mail SMTP » Settings » General » Mail » From Email
  • The info@-address of the relevant domain name

WooCommerce - Emails & events

  • WooCommerce » Settings » Emails: Emails & event
  • Compare with existing webshops of the customer in question.

WooCommerce - Emails

  • WooCommerce » Settings » Emails
  • If you scroll all the way down, you will see specific settings, such as from email address and sender name!

WooCommerce - Orders - For testing!

  • Create an order
  • Subsequently, under WooCommerce » Orders you can have the order resent to the customer and/or send a new confirmation - Handy for debugging!

WooCommerce » PDF Invoices

  • Field Shop name
  • Field Shop address

Thunderbird

Of course, Thunderbird isn't part of a WooCommerce site, but it might come handy for troubleshooting.

Webmail

Of course, TransIP's webmail client isn't part of a WooCommerce site either, but again: It might come handy.

Case: Authentication failure after cloning (May 2023)

Debugging - Thunderbird (1): I added the email address to Thunderbird, to check if it works there. This screen says two things: (1) Settings that are stored in DNS fields are available, without knowing the password. (2) The password is incorrect
Debugging - Thunderbird (2): With the correct password. All is good now

Problem

  • Webshop example.com uses the general email address of the customer for emailing
  • This webshop is cloned to example.uk
  • Now the wp-mail-smtp email test fails: Authentication error.

Additional info

Error log:

Versions:
WordPress: 6.2
WordPress MS: No
PHP: 8.0.28
WP Mail SMTP: 3.8.0

Params:
Mailer: smtp
Constants: No
ErrorInfo: SMTP Error: Could not authenticate.
Host: smtp.transip.email
Port: 465
SMTPSecure: ssl
SMTPAutoTLS: bool(true)
SMTPAuth: bool(true)

Server:
OpenSSL: OpenSSL 1.1.1f 31 Mar 2020
Apache.mod_security: No

Debug:
Email Source: WP Mail SMTP
Mailer: Other SMTP
SMTP Error: Could not authenticate.

SMTP Debug:
2023-05-09 18:03:32 Connection: opening to ssl://smtp.transip.email:465, timeout=300, options=array()
2023-05-09 18:03:32 Connection: opened
2023-05-09 18:03:32 SERVER -> CLIENT: 220 submission11.mail.transip.nl ESMTP
2023-05-09 18:03:32 CLIENT -> SERVER: EHLO example.uk
2023-05-09 18:03:32 SERVER -> CLIENT: 250-submission11.mail.transip.nl250-PIPELINING250-SIZE 37033449250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2023-05-09 18:03:32 CLIENT -> SERVER: AUTH LOGIN
2023-05-09 18:03:33 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2023-05-09 18:03:33 CLIENT -> SERVER: [credentials hidden]
2023-05-09 18:03:33 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2023-05-09 18:03:33 CLIENT -> SERVER: [credentials hidden]
2023-05-09 18:03:35 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6
2023-05-09 18:03:35 SMTP ERROR: Password command failed: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6
SMTP Error: Could not authenticate.
2023-05-09 18:03:35 CLIENT -> SERVER: QUIT
2023-05-09 18:03:35 SERVER -> CLIENT: 221 2.0.0 Bye
2023-05-09 18:03:35 Connection: closed
SMTP Error: Could not authenticate.

What I think it says:

  • There is contact between site & SMTP server
  • Authentication fails
  • There are two similar authenthication lines. Mabe the first (VXNlcm5hbWU6) line is concerning login name and the second (UGFzc3dvcmQ6) concerning password?

Possible causes

  • Password is wrong
  • By accident, this email address pretends to be another address (spoofing?) which is rejected by the server. However, the log doesn't make it beyond authentication, so this seems unlikely.

Actions

  • Add account to Thunderbird, to check if the password works there - See screenshot. Turned out that it was wrong.
  • Check documentation - Yep: Wrong password.

Conclusions

  • I had a wrong password. I don't understand how that's possible
  • Next time: Check the documentation (structure file) sooner.

Zie ook

Bronnen