Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DMA for sending email (revisit #217) #288

Open
wants to merge 5 commits into
base: v4
Choose a base branch
from

Conversation

moqmar
Copy link

@moqmar moqmar commented Feb 7, 2022

Summary

Implement solution for email sending, as discussed in #204 and also attempted earlier in #217 for v3.

This PR implements the following features

  • Install DMA
  • Make DMA configurable via environment variables
  • Document DMA usage & [NEW] add tests to build-and-test.sh
  • [NEW] Make sure the log output of DMA is redirected to STDERR by using busybox-syslogd (unfortunately DMA can only use syslog)

Explain the motivation for making this change. What existing problem does the pull request solve?

Most PHP hosters make the "mail()" function usable, so many PHP application expect it to be usable. With this image, those applications were unable to send email.

Test plan (required)

See build-and-test.sh, the commands from there can also be run manually; the mails sent with the demo credentials can be viewed on https://ethereal.email/messages.

# Let's check that we can send mail directly
TESTMAIL_ID_DIRECT=$RANDOM
docker run --rm -e DMA_BLOCKING=1 "thecodingmachine/php:${PHP_VERSION}-${BRANCH}-${BRANCH_VARIANT}" php -r "mail('[email protected]', 'Hello World ${TESTMAIL_ID_DIRECT}', 'This is an automatic test email, using a direct connection.');"

# Let's check that we can send mail through a smarthost with credentials
# Sending to an MCAST-TEST-NET IP address as that must not appear on the public internet according to RFC 5771, and will thus be unreachable for direct sending.
TESTMAIL_ID_SMARTHOST=$RANDOM
docker run --rm -e DMA_BLOCKING=1 -e DMA_CONF_SMARTHOST=smtp.ethereal.email -e DMA_CONF_PORT=587 -e DMA_CONF_SECURETRANSFER= -e DMA_CONF_STARTTLS= -e [email protected] -e DMA_AUTH_PASSWORD=pjxG3kc3VR31jQUvHz "thecodingmachine/php:${PHP_VERSION}-${BRANCH}-${BRANCH_VARIANT}" php -r "mail('[email protected]', 'Hello World ${TESTMAIL_ID_SMARTHOST}', 'This is an automatic test email, using a smarthost.');"

# Let's check that the mails came through
ETHEREAL_COOKIEJAR=$(mktemp --tmpdir ethereal-cookies.XXXXXXXXXX)
ETHEREAL_CSRF=$(curl https://ethereal.email/login -s --fail -c "${ETHEREAL_COOKIEJAR}" | grep -Pom1 '\bname="_csrf" value="\K[^"]+')
curl https://ethereal.email/login -s --fail -X POST --data-urlencode "[email protected]" --data-urlencode "password=pjxG3kc3VR31jQUvHz" --data-urlencode "_csrf=${ETHEREAL_CSRF}" -b "${ETHEREAL_COOKIEJAR}" -c "${ETHEREAL_COOKIEJAR}" >/dev/null
ETHEREAL_INBOX=$(curl https://ethereal.email/messages -s --fail -b "${ETHEREAL_COOKIEJAR}")
rm "${ETHEREAL_COOKIEJAR}"
echo "${ETHEREAL_INBOX}" | grep -F ">Hello World ${TESTMAIL_ID_DIRECT}<"
echo "${ETHEREAL_INBOX}" | grep -F ">Hello World ${TESTMAIL_ID_SMARTHOST}<"

Closing issues

Fixes #204

Checklist

  • Have you followed the guidelines in our CONTRIBUTING guide?
  • I have squashed any insignificant commits
  • This change has comments for package types, values, functions, and non-obvious lines of code

@moqmar
Copy link
Author

moqmar commented Feb 8, 2022

FYI, I'm getting the same issue in the actions when running PHP_VERSION="7.3" BRANCH="v4" VARIANT="cli" ./build-and-test.sh locally, also on the main v4 branch, so this doesn't look like it's an issue with these changes.

@mistraloz
Copy link
Collaborator

First, thx you for your PR, @moqmar. I checked and seem a good implementation for all requirement.
About the fail of CI, it's seem related to an other issue !286 (i will wait this one can be fixed to merge this PR).

I may don't have time this week to manage this issue bug the reporter said he may fix it. If not, i will try to do it at end of next week.

@mistraloz mistraloz assigned mistraloz and unassigned mistraloz Feb 8, 2022
@mistraloz mistraloz self-requested a review February 8, 2022 19:31
@mistraloz mistraloz added the enhancement Work on new feature (or any question related to new feature) label Feb 8, 2022
@mistraloz mistraloz added this to the V4 milestone Feb 8, 2022
@GlennM
Copy link

GlennM commented Jan 3, 2023

Are there any updates on this one? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Work on new feature (or any question related to new feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sending mail
3 participants