Skip to content

Can't send mail via Google Workspace #5990

@Remoddy

Description

@Remoddy

Describe the Bug

I would like BookStack to send e-mail via Gmail SMTP relay (using my Google Workspace domain).

It fails intermittently, for example first click on "Maintenance->Send test email" works fine, the next one a second later fails. The same for invite e-mail to new users. The error message is:
production.ERROR: Failed to send user invite with error: Expected response code "250" but got code "421", with message "421-4.7.0 Try again later, closing connection. (EHLO)

Steps to Reproduce

Configure SMTP relay in Google Workspace according to https://support.google.com/a/answer/2956491

Configure BookStack to use Gmail relay:
MAIL_DRIVER=smtp
MAIL_HOST=smtp-relay.gmail.com
MAIL_ENCRYPTION=tls
MAIL_FROM=foo@example.org

Try to create a new user and send them invitation e-mail

Observe it sometimes fail with red error pop-up and "production.ERROR: Failed to send user invite with error: Expected response code "250" but got code "421", with message "421-4.7.0 Try again later, closing connection. (EHLO)" in laravel.log

Expected Behaviour

The mail sending should succeed 100% of time

Screenshots or Additional Context

$ telnet smtp-relay.gmail.com 587
Trying 142.250.110.28...
Connected to smtp-relay.gmail.com.
Escape character is '^]'.
220 smtp-relay.gmail.com ESMTP a640dd1662f3a-a38921cc907sm153220566b.83 - gsmtp
EHLO [127.0.0.1]
421-4.7.0 Try again later, closing connection. (EHLO)
421-4.7.0  For more information, go to
421 4.7.0  https://support.google.com/a/answer/3221692 a640dd1662f3a-a38921cc907sm153220566b.83 - gsmtp
Connection closed by foreign host.
$ 
$ telnet smtp-relay.gmail.com 587
Trying 142.250.110.28...
Connected to smtp-relay.gmail.com.
Escape character is '^]'.
220 smtp-relay.gmail.com ESMTP 2810306940e0a-594af1f2ac4sm256491fe81.0 - gsmtp
EHLO foo.example.org
250-smtp-relay.gmail.com at your service, [111.234.56.123]
250-SIZE 157286400
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
  • I confirmed with "tcpdump port 587 -s 0 -A" that indeed BookStack says EHLO [127.0.0.1] when talking to Google. Sometimes it works fine and email is sent, sometimes Google replies with error and sending fails.
  • BookStack is served at foo.example.org, APP_URL is set to https://foo.example.org
  • Editing getLocalDomain() in /var/www/bookstack/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:132 from "return $this->domain;" to "return 'foo.example.org';" fixed all the problems so far.
  • After a quick glance at SMTP RFC https://www.rfc-editor.org/rfc/rfc5321 it looks to me that while IP address may be allowed sometimes, using domain is always preferred if available. I guess most actual mail servers prefer that too. So I would appreciate BookStack using the domain from APP_URL while introducing itself to mail servers.

Browser Details

No response

Exact BookStack Version

25.12.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions