-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Email does not work #30
Comments
Yeah... This was a hole we've had on our radar for a long time now, but |
It looks like WP actually uses something called PHPMailer under the hood, which does support SMTP, but it requires a custom hook for configuration: http://codex.wordpress.org/Plugin_API/Action_Reference/phpmailer_init#Examples |
@md5 An alternative is to use a service like mailchimp and Mandrill. I know these are paying services, and not on your own service but the good thing (for Mandrill) is that you can opt out at any moment. My experience is, your server emails will be probably put in SPAM folder. This is not the case for Mandrill. |
@omarabid using Mailchimp or Mandrill still requires using SMTP, which isn't supported out of the box by Wordpress under Linux. As I mentioned in an earlier comment, it would be possible to add one of the WP plugins that supports SMTP, but I don't think it would be reasonable for a generic Wordpress image to include specific plugins. In my case, I was using |
using Mailchimp or Mandrill still requires using SMTP No, otherwise, what's the point of using Mandrill. |
Ok, you're right that you can use Mandrill with their REST API instead of SMTP, but that requires installing this plugin or some other plugin that knows how to use that API. As for the point of using Mandrill with SMTP, there are a ton of reasons you might want to do that, including open tracking, click tracking, deliverability concerns, email volume, etc. Not of those advantages of the Mandrill service rely on using the REST API. |
@md5 I was just suggesting a solution. Obviously, this should be available/fixed for the official Docker repo. |
Wondering how modular you can make the smtp solution> A nice implementation that I've seen is this one https://github.com/catatnight/docker-postfix , but it does bolt on TLS and and OpenDKIM. Perhaps it could be paired down to just postfix? I'm assuming it would only be used via container link so you don't need TLS. DKIM is fall back to avoid DNS shenanigans, admittedly not having it or SSP will probably cause some filters to flag you as spammy. Thoughts? I think it's time to retreat to the lab 😀 |
We are using SSMTP to relay to our main mailserver.
We have a sed in the Dockerfile that changes the mailhub, rewritedomain and removes the hostname line from the ssmtp file (this way it gets the container id as the hostname)
This works really well, and as ssmtp isn't a daemon, it doesn't require any process management |
@booyaa I don't like that the Postfix container you mention is using I think the real issue is that PHP is still going to expect a working I still think the best that can be done here without assuming too much is simply to document the options. |
Random musing: this problem would be a great candidate for a mail service docker-compose.yml firing up smtp, imap, spam assassin, clamav and webmail |
@booyaa 👍 |
One good option is to configure SSMTP with ENV variables. |
If this is an old post, or there has previously been a resolution please disregard. One quick way of getting mail working inside the container is to install msmtp. Then, in a configuration file(example: msmtp):
Copy this to /etc/ inside the container Update the php.ini or set the sendmail_path variable like so: sendmail_path = "/usr/bin/msmtp -t -i" TL;DR |
@md5 Any updates on this? I like the new container for SMTP approach. It separates concerns. However, this seems like a WordPress issue for me. |
@omarabid I'm not aware of any developments on this issue other than what you can read in this thread. |
Perhaps since a bunch of you have been able to successfully run Via a simple |
Have you tried Try something like this: $ docker run -t --rm debian:jessie 'apt-get update && apt-get install -y telnet && telnet server-address port' If that hangs too, then the problem is probably being caused by firewall rules on the host (outside the container). This can happen if the server you're trying to contact is on an RFC 1918 private subnet like something under 192.168.0.0/16 and your host thinks it should drop packets from the Docker bridge network. |
Yeah, did it, and it works fine. it responds. so don't think it's networking related. Anyways ended up ditching |
That's odd. I haven't seen sendmail time out for reasons other than packet drops, but perhaps the SMTP server was overloaded or something? It would be good to get to the bottom of the issue if only for the sake of other users who hit problems using ssmtp. BTW, I should point out that |
Ok, just to continue the discussion, here is a working example with |
So I've managed to come up with a solution that involves another container and a WordPress plugin. The container is running an SMTP client that I wrote (named Hectane) and the WordPress plugin routes all calls to Here are the commands to get it up and running:
Once the containers are up and running, it's simply a matter of installing and activating this WordPress plugin and changing the hostname to "mail" in "Settings". Once that's done, all emails will be sent through Hectane and delivered via SMTP. |
Hi @nathan-osman, is it possible use |
I am using SendGrid for emails. It is super easy to set up with one of the many WP plugins and then you will send emails through an API while getting insights on open rate, bounce rate etc. |
I presume you could use anyone of the smtp plugins to get this to work? |
Don't use ssmtp on new setups. It isn't serviced and debian packages are orphaned. Use msmtp instead. /etc/msmtprc
With recent versions (not yet available in alpine and debian) you can also set Also set this php configuration value: |
I agree with the above. Let me propose my simple configuration that only forwards mail to my host's postfix (you could also have a dedicated container for sending mail, which would alleviate the need for fixed container network configuration): /etc/msmtprc (container)
You also need to configure your host's postfix to accept requests from docker: /etc/postfix/main.cf (host)
This is minimal: expect your mails to end in spam folders. But it works! EDIT: I ran into trouble setting |
I had the same problem. So I tried to find a solution. I've found several solutions and tested all of them at my site (to make sure they worked). It would be too long to post them here. So I have created a separate article: https://www.wpdiaries.com/mail-functionality-for-official-docker-wordpress-image/ The article contains detailed examples of adding Postfix in a separate container. There are 2 such examples based on 2 different images (one has digital signing e-mails with DKIM and the other one works without DKIM). Also, I have added an example of adding Postfix directly to a WordPress container, but this solution is not recommended (it is better to have 1 responsibility for 1 container as it is described in the official Docker best practices). I've made sure the e-mail sending functionality works in each of the listed examples. I hope this will be useful for people who got problems with sending e-mail from WordPress in Docker. At least I did my best to provide as detailed and clear examples as I could. |
possibly use Mailhog? Other images have used this Forward Message to mailhogRUN curl --location --output /usr/local/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 && docker-compose: |
Hello, I have found a much better solution than using msmtp, ssmtp, mailhog or any other SMTP client for that matter. Wordpress is apparently bundled with PHPMailer - I did not realize that it came included with Wordpress by default. This means with a little creativity we are able to configure it using the Here is an example written in YAML for our Kubernetes deployment:
Of course, with a little tweaking you can apply the same setup in Docker, docker-compose and more, and at least in our case this eliminates the need for building a custom Docker image or running an MTA in a separate container. Hope this helps, |
does anyone know how to translate this into a docker-compose.yml? Thank you so much! |
Hi @derspotter, you could try something like this (note the double $$ to prevent docker compose from interpreting environment variables in the PHP code): (NOTE: I do not use Docker compose and I don't know the best way to handle storing sensitive info such as secrets. This is just a proof of concept showing how to translate a quick setup to a docker-compose file:
|
Thank you so much!!! it works :)) |
Thanks @joeldeteves for the In case it saves someone else a few frustrating hours, it seems like the I am not sure what exactly is missing but from inside a container using the |
I'm not able to reproduce this problem; I use alpine versions for all my deployments (currently running You might want to double-check your config and/or firewall. |
@joeldeteves Interesting. I'm on macOS. It doesn't work for me. I'm not sure this is the right place for this tangent but maybe it is relevant and helps others. Super-simple
|
I still can't reproduce this (I used the compose example you provided above, both containers are able to resolve just fine) however I am running Ubuntu. It is very probable that this is something specific to your environment, quite possibly Mac-OS specific. You may want to run some more tests such as testing from a VM, but I do not believe it is related to the alpine image. |
Thank you this worked with docker-compose! I created a separate gmail account that's only used to send mails on a wp-site of mine. If you use gmail as I did, you have to enable less secure apps in your gmail settings https://support.google.com/accounts/answer/6010255?hl=en |
Hello everyone.
The exact RUN statement is bellow:
The exact Php's Dockerfile is here https://github.com/sceptic30/php8-msmtp/blob/main/Dockerfile For those that they just want to download the images use these commands (currently the most up to date):
And for Wordpress:
After that, follow instructions given here https://github.com/sceptic30/php8-msmtp#create-configuration-files-for-msmtp for the confuguration files that needs to be bind-mount to the container file system, and you should be good to go. |
I have a running dovecot/postfix stack at arbitrary internal hostname require_once(ABSPATH .'wp-includes/plugin.php');
// configure phpmailer with SMTP before sending emails
add_action('phpmailer_init', function($mailer) {
$mailer->isSMTP();
$mailer->Host = "dovecot.my";
$mailer->SMTPAuth = true;
$mailer->Username = "[email protected]";
$mailer->Password = "pass";
$mailer->Port = 587;
});
// from_email defaults to 'wordpress@$sitename', which seems to be wordpress@localhost by default
// use this filter to make sure it matches your smtp host
add_filter('wp_mail_from', function($from) {
return "[email protected]";
});
// optional: error logging in case phpmailer fails
add_action('wp_mail_failed', function($wperror) {
error_log(implode("; ", $wperror->get_error_messages()));
}); I put the above in a Just be aware that this is probably terrible security, don't use in production. Tested on wordpress:5.7.2 |
If I add a plugin via the settings interface once the container is running, is that persisted? I'm using the example |
As long as you persist |
@Losmoges does not work, writes to log |
If anyone's interested, my approach to solve this was as follows. In docker-compose.yml:
msmtp-php.ini:
msmtprc:
Seems to work in my very basic testing (I'm a complete Wordpress newbie; have only been looking at this to get a site up and running that somebody has asked me to host). |
I noticed that I can send emails by wrapping wrapped-entrypoint.sh #!/bin/bash
# Start the sendmail daemon
/usr/sbin/sendmail -bd
# Execute the original entrypoint script
exec docker-entrypoint.sh "$@" Dockerfile FROM docker.io/library/wordpress:php7.4-apache
# Install sendmail
RUN apt-get update && apt-get install -y sendmail && apt-get clean
# Copy the wrapped entrypoint script
COPY wrapped-entrypoint.sh /usr/local/bin/
# Make the script executable
RUN chmod +x /usr/local/bin/wrapped-entrypoint.sh
# Use the wrapped entrypoint
ENTRYPOINT ["wrapped-entrypoint.sh"] |
Thanks for this. It seems like this is the most straightforward solution that doesn't involve rebuilding the container, which is a huge plus. Still works perfectly. |
hi, thanks a lot for your solution |
I think the main reason to avoid putting secrets in the docker-compose yaml is to prevent accidentally committing a real secret in source control. |
In order to work around the issue I created a very simple plugin that just expects certain SMTP variables to exist in Then all it takes is adding the plugin to the proper place ( |
I stumbled upon this issue today. I took a look into the SSL support in #!/bin/sh
SENDER_ADDRESS="[email protected]"
SMTP_HOST="smtp.example.com:465"
SMTP_USERNAME="[email protected]"
SMTP_PASSWORD="p4ssw0rd"
/usr/sbin/sendmail \
-t \
-H "openssl s_client -quiet -connect $SMTP_HOST" \
-au$SMTP_USERNAME \
-ap$SMTP_PASSWORD \
-f $SENDER_ADDRESS Please note that there MUST NOT be a whitespace character before username and password. I saved the previous script on my docker host and mounted it to sendmail_path=/usr/local/bin/sendmail This works for me without any further Wordpress configuration. If you are worried about passing the password on CLI: #!/bin/sh
SENDER_ADDRESS="[email protected]"
SMTP_HOST="smtp.example.com:465"
/usr/sbin/sendmail \
-t \
-H "openssl s_client -quiet -connect $SMTP_HOST" \
-amLOGIN 4<user_pass.txt \
-f $SENDER_ADDRESS AFAIK |
As it currently stands, anything in Wordpress that needs to send email is broken. The
wp_mail
function that is used for sending out email by default is a thin wrapper over PHP'smail
function, which defaults to calling/usr/sbin/sendmail -t -i
(cf. http://php.net/manual/en/mail.configuration.php). There arephp.ini
settings for SMTP, but they are only used on Windows.For my own work based on this image, I've been installing
ssmtp
and configuring it to use an external relay host for SMTP, but that's clearly not a turnkey solution for everyone. It also looks like there are many Wordpress plugins that provide SMTP support, but I don't think that installing any of them by default in this image seems reasonable.Perhaps all of this should just be documented, but I wanted to get it on your radar.
The text was updated successfully, but these errors were encountered: