Azure / wordpress-linux-appservice

MIT License
111 stars 71 forks source link

Cannot Send Email from Word Press with Azure Communication Plugin #110

Closed antonymillar closed 1 year ago

antonymillar commented 1 year ago

Hi Radhika,

Apologies in the delay raising this ticket.

I have enabled WP Debugging and have a bit more info below.

App Service Configuration is the following :

Name : WP_EMAIL_CONNECTION_STRING Value : endpoint=https://XXXXXXX.communication.azure.com/;senderaddress=help@XXXXXXXX.com;accesskey=XXXXXXXXXXXXXXXXXX

Note : I have deliberately changed the access key for this ticket, but I have triple checked it, I have also run a "try email test" in the portal.

Initially this all did work for one day, and if it helps those two test emails where sent on 22nd August 2023 at 5pm

ever since it has stopped working.

Here is the output from the word press debug :

c8f586a9742d:/var/www/html# tail -f /var/log/php-fpm/php-fpm.www.log [08-Sep-2023 14:23:09 UTC] PHP Warning: Undefined array key "status" in /var/www/wordpress/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email/admin/mailer/class-azure_app_service_email-controller.php on line 163 [08-Sep-2023 14:23:09 UTC] PHP Warning: Undefined array key "status" in /var/www/wordpress/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email/admin/mailer/class-azure_app_service_email-controller.php on line 163 [08-Sep-2023 14:23:09 UTC] PHP Warning: Undefined array key "status" in /var/www/wordpress/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email/admin/mailer/class-azure_app_service_email-controller.php on line 163

Plugin. App Service Email Plugin enables seamless integration with the Azure Email Communication Service, empowering your WordPress website with the ability to leverage Microsoft Azure's robust infrastructure for email delivery.

Version : 1.0.0

Thanks in advance

Tony

antonymillar commented 1 year ago

Good Afternoon @rabollin just wanted to follow this up with it being a week, have you managed to take a look into my issue? is there anything you need from me? Thanks in advance

rabollin commented 1 year ago

@antonymillar - acknowledging the issue, somehow this issue got fallen off of my list. Will get back to you shortly. Now we have enabled logging in Admin page also, in Plugin configuration section you can view the list of emails sent and their status. You may check it out once.

antonymillar commented 1 year ago

Good afternoon @rabollin thanks for getting back to me, no worries about this falling off the list I happens to all of us, and your help is very much appreciated . I have just logged into the WP Admin and have had a good look around for the plugin configuration but I cannot seem to see it, can you maybe guide me?

I did install these plugin to help me trouble shoot to give you more info :

WP Test Email is allows you to test if your WordPress installation is sending mail or not. Version 1.1.6 | By [Boopathi Rajan]

This is the plugin I used to test emails that did work initially but is now reporting email not sent.

and then this

Email Log Logs every email sent through WordPress Version 2.4.8 | By [Sudar]

This shows a log of emails, all of which state they have been sent, but as we know they haven't so I am not sure how good this plug in is for logging, however I can confirm when I deactivate your plugin the log shows Not sent.

Hope this helps anything else you need from me just let me know.

Thanks

Tony

bmanjwani commented 1 year ago

@antonymillar Please use this link to download the zip file of latest plugin code. And please let us know if you see any logs being captured in our plugin.

Secondly seeing your sender address , it seems you are using custom domain for sending emails. Can you confirm you if you have follwed the quick start guide to setup custom domain.

In your previous comment , you mentioned that email integration did work for you? so was it with azure managed domain or custom domain?

antonymillar commented 1 year ago

Hi @bmanjwani thanks for getting back to me.

I have installed the latest version of the plugin, and can now see the "Azure Email Logs" on the left, after trying again each test is failing with the following error :

"Denied by the resource provider.Click here for more support."

I am using a custom domain for sending and can confirm I did follow the guide, and my custom domain does have verified ticks against domain status, SPF, DKIM and DKIM2. ( I have also just double checked all DNS records are still in place which they are)

I can also test the sending of the email from the Azure portal without issue.

When I initially set this up, it worked straight away, and that was with the custom domain that I have configured, I have not changed any settings, the DNS records are still in place, I have not changed the access key's and they remain the same, the from address is also set-up correctly in the azure portal.

Here is the latest output from the WP debug log ::

[18-Sep-2023 13:21:11 UTC] PHP Warning: Undefined array key "status" in /var/www/wordpress/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email-1/admin/mailer/class-azure_app_service_email-controller.php on line 173 [18-Sep-2023 13:21:11 UTC] PHP Warning: Undefined array key "status" in /var/www/wordpress/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email-1/admin/mailer/class-azure_app_service_email-controller.php on line 173 [18-Sep-2023 13:21:11 UTC] PHP Warning: Undefined array key "status" in /var/www/wordpress/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email-1/admin/mailer/class-azure_app_service_email-controller.php on line 173

Can you see anything on your side against our subscription ID?

Anything you need me to try just let me know.

Thanks in advance

Antony

bmanjwani commented 1 year ago

@antonymillar, could you please provide your email address? I'd like to schedule a time to review your setup to help us troubleshoot the issue. Based on the logs, it appears that an incorrect signature may be causing this authentication error.

afspo commented 1 year ago

Hi both,

If/when you find a solution could you please write it up here? I'm not sure that I have the same problem, but having issues with getting account creation/password emails sent out.

Cheers

MattWhite-personal commented 1 year ago

+1 on this issue need to dig into the debug logs to verify i have the same errors as @antonymillar has reported. Plugin was downloaded and installed yesterday and again am using a custom domain that is fully verified. I also have raised a support ticket via Azure Portal but can see little to nothing on the Azure side that is out of place.

Is there a requirement that the wordpress email address setting in Settings -> General to the FROM address that is set in the Email Communication service?

rabollin commented 1 year ago

@MattWhite-personal - Can you please check if your App Service application settings - the Sender address should change as per your custom domain.

Below is the application setting :

Name: WP_EMAIL_CONNECTION_STRING. Value: “endpoint=;senderaddress=;accesskey=

Replace and with the Azure communication service endpoint and primary key values, replace with MailFrom Address

rabollin commented 1 year ago

Hi both,

If/when you find a solution could you please write it up here? I'm not sure that I have the same problem, but having issues with getting account creation/password emails sent out.

Cheers

@antonymillar - Sent you a meeting request to troubleshoot issue in your environment, that can help for a quicker resolution

MattWhite-personal commented 1 year ago

The senderaddress is set to the value that is in the email communication service and have matched that to what is in the wordpress site but still get the same error message

rabollin commented 1 year ago

@MattWhite-personal - We can directly connect to debug the issue in your environment, can you please share your email address for blocking time for troubleshooting session.

MattWhite-personal commented 1 year ago

I get the same entry in the logs

[24-Sep-2023 17:06:24 UTC] PHP Warning:  Undefined array key "status" in /home/site/wwwroot/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email/admin/mailer/class-azure_app_service_email-controller.php on line 173
[24-Sep-2023 17:06:24 UTC] PHP Warning:  Undefined array key "status" in /home/site/wwwroot/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email/admin/mailer/class-azure_app_service_email-controller.php on line 173
[24-Sep-2023 17:06:25 UTC] PHP Warning:  Undefined array key "status" in /home/site/wwwroot/wp-content/plugins/Azure-Wordpress-on-Linux-App-Service-plugins-main-app_service_email/admin/mailer/class-azure_app_service_email-controller.php on line 173
MattWhite-personal commented 1 year ago

@rabollin - im not sure if the error is specifically related to wordpress or the implementation of the code - is it possible to share any code samples here for how the plugin is generating the relevant messages to run against the service oustide of the container running wordpress? Would be handy to rule in/out the communication service or the plugin code itself

rabollin commented 1 year ago

https://github.com/Azure/Wordpress-on-Linux-App-Service-plugins/blob/main/app_service_email/admin/mailer/class-azure_app_service_email-controller.php - We parse the connection string here to connect to ACS to send the emails.

Can you please share what is the exact error message you are facing?

MattWhite-personal commented 1 year ago

I think this code is a red herring in the current plugin having read the API reference - https://learn.microsoft.com/en-us/rest/api/communication/email/send?tabs=HTTP

Looking at the API definition there is no status value that is returned if the error code is not a 202. To clear this up I would put the status inside the if statement looking for the return value

if ($response_code === 200 || ($response_code === 202 && $status === 'Running')) {
  $status = $body_array['status'];
  $logemail->email_logger_capture_emails($to, $subject, 'Success', '');
  return true;
}

I have tried changing the api version value given that following page - https://learn.microsoft.com/en-us/rest/api/communication/#communication-services-resource-groups - suggests that it should be 2021-10-01-preview but also the methods page says the api version is 2023-03-31 and the method in the class is currently using 2023-01-15-preview

The error message that is being logged is coming back from the API service from what I can see but cant see the errorcode that is returning the message to support troubleshooting is it possible to log more from the errormessage that came back or to add to the debug log to drop the whole error response into the log?

https://learn.microsoft.com/en-us/rest/api/communication/email/send?tabs=HTTP#errorresponse

It's been a while since I have done much PHP based work but think there is something in the error response that would help to troubleshoot further

bmanjwani commented 1 year ago

@MattWhite-personal Can you please email us (wordpressonazure@microsoft.com) and share your resource name subscription id and screenshot of the error message being captured in the email plugin. Secondly . Were you able to send emails at first place (i.e. with azure managed domain)?

Happy to have a working session with you. Please share your email id and timezone , so that we can block some time.

MattWhite-personal commented 1 year ago

@MattWhite-personal Can you please email us (wordpressonazure@microsoft.com) and share your resource name subscription id and screenshot of the error message being captured in the email plugin. Secondly . Were you able to send emails at first place (i.e. with azure managed domain)?

Happy to have a working session with you. Please share your email id and timezone , so that we can block some time.

The specific error I see in the log is

Denied by the resource provider.Click here for more support

I can drop an email over the wordpressonazure mailbox with more info including the support case I raised this morning

MattWhite-personal commented 1 year ago

@MattWhite-personal Can you please email us (wordpressonazure@microsoft.com) and share your resource name subscription id and screenshot of the error message being captured in the email plugin. Secondly . Were you able to send emails at first place (i.e. with azure managed domain)?

Happy to have a working session with you. Please share your email id and timezone , so that we can block some time.

Email on it's way over

bmanjwani commented 1 year ago

@antonymillar, your cooperation has been greatly appreciated. In order to keep everyone informed and to help prevent similar challenges in the future, it was identified that a trailing slash ("/") at the end of the endpoint URL was the root cause of the issue. AppSetting "WP_EMAIL_CONNECTION_STRING" should follow this format Name: WP_EMAIL_CONNECTION_STRING. Value: “endpoint=;senderaddress=< sender-address>;accesskey=To prevent authorization issues, please do not include trailing slashes in the 'endpoint'.

we will be updating the email integration documentation with this essential information soon.

@afspo @MattWhite-personal FYI

MattWhite-personal commented 1 year ago

thanks @bmanjwani - will give this a go in terms of changes in the app variable. I dont know how long lived the plugin will be but it may be sensible to breakout the various settings for domain, from address, key into separate variables so they are all pulled through together - this may be a breaking change in terms of how the plugin can work but a future release can /should allow for the management of the https://removal (its already in today) and the trailing / detection removal in a future release

Other comments above may not be relevant to resolving the issue but would suggest for future extensibility they are incorporated into the plugin release.

MattWhite-personal commented 1 year ago

but can confirm dropping the trailing / does resolve the issue for me - many thanks for the resolution

rabollin commented 1 year ago

Closing the issue as fixed.