nextcloud / nextcloud/mail

Sending mail failed - no hint for user why it failed

Open
#9,498 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop bug
Dominant language
JavaScript
Stars
1k
Forks
348
Avg merge
12h 28m
Merged PRs (30d)
91

Description

Steps to reproduce
  1. Send an e-mail to a non-existent address
  2. See sending error message
  3. Don't see anything why it failed
Expected behavior

Message to user why the message could not be sent

Actual behavior

Generic error message that mail could not be sent

Mail app version

3.5.7

Mailserver or service

SMTP server of our hosting

Operating system

No response

PHP engine version

PHP 8.2

Web server

Apache (supported)

Database

PostgreSQL

Additional info

I think this error only happens when the SMTP server that is used for sending the message is also responsible for the recipient's mailbox. I checked it with a non-existing address on another domain and the mail was sent and I got an NDR back.

Server log

{
	"reqId": "guwdo7gmXfsCNY7oOaCu",
	"level": 3,
	"time": "2024-03-26T12:54:00+00:00",
	"remoteAddr": "62.225.12.220",
	"user": "christian.hartmann",
	"app": "mail",
	"method": "POST",
	"url": "/apps/mail/api/outbox/979",
	"message": "Could not send message: Message could not be delivered - the address was not found, is unknown, or is not receiving messages.",
	"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
	"version": "28.0.3.2",
	"exception": {
		"Exception": "OCA\\Mail\\Exception\\ServiceException",
		"Message": "Could not send message: Message could not be delivered - the address was not found, is unknown, or is not receiving messages.",
		"Code": 5,
		"Trace": [
			{
				"file": "/var/www/html/custom_apps/mail/lib/Service/MailTransmission.php",
				"line": 343,
				"function": "sendMessage",
				"class": "OCA\\Mail\\Service\\MailTransmission",
				"type": "->",
				"args": [
					[
						"OCA\\Mail\\Model\\NewMessageData"
					],
					null,
					null
				]
			},
			{
				"file": "/var/www/html/custom_apps/mail/lib/Service/OutboxService.php",
				"line": 142,
				"function": "sendLocalMessage",
				"class": "OCA\\Mail\\Service\\MailTransmission",
				"type": "->",
				"args": [
					[
						"OCA\\Mail\\Account"
					],
					[
						"OCA\\Mail\\Db\\LocalMessage",
						979
					]
				]
			},
			{
				"file": "/var/www/html/custom_apps/mail/lib/Controller/OutboxController.php",
				"line": 247,
				"function": "sendMessage",
				"class": "OCA\\Mail\\Service\\OutboxService",
				"type": "->",
				"args": [
					[
						"OCA\\Mail\\Db\\LocalMessage",
						979
					],
					[
						"OCA\\Mail\\Account"
					]
				]
			},
			{
				"file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
				"line": 230,
				"function": "send",
				"class": "OCA\\Mail\\Controller\\OutboxController",
				"type": "->",
				"args": [
					979
				]
			},
			{
				"file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
				"line": 137,
				"function": "executeController",
				"class": "OC\\AppFramework\\Http\\Dispatcher",
				"type": "->",
				"args": [
					[
						"OCA\\Mail\\Controller\\OutboxController"
					],
					"send"
				]
			},
			{
				"file": "/var/www/html/lib/private/AppFramework/App.php",
				"line": 184,
				"function": "dispatch",
				"class": "OC\\AppFramework\\Http\\Dispatcher",
				"type": "->",
				"args": [
					[
						"OCA\\Mail\\Controller\\OutboxController"
					],
					"send"
				]
			},
			{
				"file": "/var/www/html/lib/private/Route/Router.php",
				"line": 315,
				"function": "main",
				"class": "OC\\AppFramework\\App",
				"type": "::",
				"args": [
					"OCA\\Mail\\Controller\\OutboxController",
					"send",
					[
						"OC\\AppFramework\\DependencyInjection\\DIContainer"
					],
					[
						"979",
						"mail.outbox.send"
					]
				]
			},
			{
				"file": "/var/www/html/lib/base.php",
				"line": 1069,
				"function": "match",
				"class": "OC\\Route\\Router",
				"type": "->",
				"args": [
					"/apps/mail/api/outbox/979"
				]
			},
			{
				"file": "/var/www/html/index.php",
				"line": 39,
				"function": "handleRequest",
				"class": "OC",
				"type": "::",
				"args": []
			}
		],
		"File": "/var/www/html/custom_apps/mail/lib/Service/MailTransmission.php",
		"Line": 273,
		"Previous": {
			"Exception": "Horde_Mime_Exception",
			"Message": "Message could not be delivered - the address was not found, is unknown, or is not receiving messages.",
			"Code": 5,
			"Trace": [
				{
					"file": "/var/www/html/custom_apps/mail/vendor/bytestream/horde-mime/lib/Horde/Mime/Mail.php",
					"line": 479,
					"function": "send",
					"class": "Horde_Mime_Part",
					"type": "->",
					"args": [
						"recipient.address@domain",
						[
							"Horde_Mime_Headers"
						],
						[
							"Horde_Mail_Transport_Smtphorde",
							"\r\n",
							false
						]
					]
				},
				{
					"file": "/var/www/html/custom_apps/mail/lib/Service/MailTransmission.php",
					"line": 271,
					"function": "send",
					"class": "Horde_Mime_Mail",
					"type": "->",
					"args": [
						[
							"Horde_Mail_Transport_Smtphorde",
							"\r\n",
							false
						],
						false,
						false
					]
				},
				{
					"file": "/var/www/html/custom_apps/mail/lib/Service/MailTransmission.php",
					"line": 343,
					"function": "sendMessage",
					"class": "OCA\\Mail\\Service\\MailTransmission",
					"type": "->",
					"args": [
						[
							"OCA\\Mail\\Model\\NewMessageData"
						],
						null,
						null
					]
				},
				{
					"file": "/var/www/html/custom_apps/mail/lib/Service/OutboxService.php",
					"line": 142,
					"function": "sendLocalMessage",
					"class": "OCA\\Mail\\Service\\MailTransmission",
					"type": "->",
					"args": [
						[
							"OCA\\Mail\\Account"
						],
						[
							"OCA\\Mail\\Db\\LocalMessage",
							979
						]
					]
				},
				{
					"file": "/var/www/html/custom_apps/mail/lib/Controller/OutboxController.php",
					"line": 247,
					"function": "sendMessage",
					"class": "OCA\\Mail\\Service\\OutboxService",
					"type": "->",
					"args": [
						[
							"OCA\\Mail\\Db\\LocalMessage",
							979
						],
						[
							"OCA\\Mail\\Account"
						]
					]
				},
				{
					"file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
					"line": 230,
					"function": "send",
					"class": "OCA\\Mail\\Controller\\OutboxController",
					"type": "->",
					"args": [
						979
					]
				},
				{
					"file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
					"line": 137,
					"function": "executeController",
					"class": "OC\\AppFramework\\Http\\Dispatcher",
					"type": "->",
					"args": [
						[
							"OCA\\Mail\\Controller\\OutboxController"
						],
						"send"
					]
				},
				{
					"file": "/var/www/html/lib/private/AppFramework/App.php",
					"line": 184,
					"function": "dispatch",
					"class": "OC\\AppFramework\\Http\\Dispatcher",
					"type": "->",
					"args": [
						[
							"OCA\\Mail\\Controller\\OutboxController"
						],
						"send"
					]
				},
				{
					"file": "/var/www/html/lib/private/Route/Router.php",
					"line": 315,
					"function": "main",
					"class": "OC\\AppFramework\\App",
					"type": "::",
					"args": [
						"OCA\\Mail\\Controller\\OutboxController",
						"send",
						[
							"OC\\AppFramework\\DependencyInjection\\DIContainer"
						],
						[
							"979",
							"mail.outbox.send"
						]
					]
				},
				{
					"file": "/var/www/html/lib/base.php",
					"line": 1069,
					"function": "match",
					"class": "OC\\Route\\Router",
					"type": "->",
					"args": [
						"/apps/mail/api/outbox/979"
					]
				},
				{
					"file": "/var/www/html/index.php",
					"line": 39,
					"function": "handleRequest",
					"class": "OC",
					"type": "::",
					"args": []
				}
			],
			"File": "/var/www/html/custom_apps/mail/vendor/bytestream/horde-mime/lib/Horde/Mime/Part.php",
			"Line": 1642,
			"Previous": {
				"Exception": "Horde_Mail_Exception",
				"Message": "Message could not be delivered - the address was not found, is unknown, or is not receiving messages.",
				"Code": 5,
				"Trace": [
					{
						"file": "/var/www/html/custom_apps/mail/vendor/bytestream/horde-mime/lib/Horde/Mime/Part.php",
						"line": 1620,
						"function": "send",
						"class": "Horde_Mail_Transport_Smtphorde",
						"type": "->",
						"args": [
							"recipient.address@domain",
							[
								"Christian Hartmann <sender.address@domain>",
								"recipient.address@domain",
								"",
								"Test",
								"<20240326125355.Horde.eC1lnQkQQ6-5alzMo3hzVZc@cloud.domain.tld>",
								"And 5 more entries, set log level to debug to see all entries"
							],
							null
						]
					},
					{
						"file": "/var/www/html/custom_apps/mail/vendor/bytestream/horde-mime/lib/Horde/Mime/Mail.php",
						"line": 479,
						"function": "send",
						"class": "Horde_Mime_Part",
						"type": "->",
						"args": [
							"recipient.address@domain",
							[
								"Horde_Mime_Headers"
							],
							[
								"Horde_Mail_Transport_Smtphorde",
								"\r\n",
								false
							]
						]
					},
					{
						"file": "/var/www/html/custom_apps/mail/lib/Service/MailTransmission.php",
						"line": 271,
						"function": "send",
						"class": "Horde_Mime_Mail",
						"type": "->",
						"args": [
							[
								"Horde_Mail_Transport_Smtphorde",
								"\r\n",
								false
							],
							false,
							false
						]
					},
					{
						"file": "/var/www/html/custom_apps/mail/lib/Service/MailTransmission.php",
						"line": 343,
						"function": "sendMessage",
						"class": "OCA\\Mail\\Service\\MailTransmission",
						"type": "->",
						"args": [
							[
								"OCA\\Mail\\Model\\NewMessageData"
							],
							null,
							null
						]
					},
					{
						"file": "/var/www/html/custom_apps/mail/lib/Service/OutboxService.php",
						"line": 142,
						"function": "sendLocalMessage",
						"class": "OCA\\Mail\\Service\\MailTransmission",
						"type": "->",
						"args": [
							[
								"OCA\\Mail\\Account"
							],
							[
								"OCA\\Mail\\Db\\LocalMessage",
								979
							]
						]
					},
					{
						"file": "/var/www/html/custom_apps/mail/lib/Controller/OutboxController.php",
						"line": 247,
						"function": "sendMessage",
						"class": "OCA\\Mail\\Service\\OutboxService",
						"type": "->",
						"args": [
							[
								"OCA\\Mail\\Db\\LocalMessage",
								979
							],
							[
								"OCA\\Mail\\Account"
							]
						]
					},
					{
						"file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
						"line": 230,
						"function": "send",
						"class": "OCA\\Mail\\Controller\\OutboxController",
						"type": "->",
						"args": [
							979
						]
					},
					{
						"file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
						"line": 137,
						"function": "executeController",
						"class": "OC\\AppFramework\\Http\\Dispatcher",
						"type": "->",
						"args": [
							[
								"OCA\\Mail\\Controller\\OutboxController"
							],
							"send"
						]
					},
					{
						"file": "/var/www/html/lib/private/AppFramework/App.php",
						"line": 184,
						"function": "dispatch",
						"class": "OC\\AppFramework\\Http\\Dispatcher",
						"type": "->",
						"args": [
							[
								"OCA\\Mail\\Controller\\OutboxController"
							],
							"send"
						]
					},
					{
						"file": "/var/www/html/lib/private/Route/Router.php",
						"line": 315,
						"function": "main",
						"class": "OC\\AppFramework\\App",
						"type": "::",
						"args": [
							"OCA\\Mail\\Controller\\OutboxController",
							"send",
							[
								"OC\\AppFramework\\DependencyInjection\\DIContainer"
							],
							[
								"979",
								"mail.outbox.send"
							]
						]
					},
					{
						"file": "/var/www/html/lib/base.php",
						"line": 1069,
						"function": "match",
						"class": "OC\\Route\\Router",
						"type": "->",
						"args": [
							"/apps/mail/api/outbox/979"
						]
					},
					{
						"file": "/var/www/html/index.php",
						"line": 39,
						"function": "handleRequest",
						"class": "OC",
						"type": "::",
						"args": []
					}
				],
				"File": "/var/www/html/custom_apps/mail/vendor/bytestream/horde-mail/lib/Horde/Mail/Transport/Smtphorde.php",
				"Line": 145,
				"Previous": {
					"Exception": "Horde_Smtp_Exception_Recipients",
					"Message": "Message could not be delivered - the address was not found, is unknown, or is not receiving messages.",
					"Code": 5,
					"Trace": [
						{
							"file": "/var/www/html/custom_apps/mail/vendor/nextcloud/horde-smtp/lib/Horde/Smtp.php",
							"line": 667,
							"function": "_getResponse",
							"class": "Horde_Smtp",
							"type": "->",
							"args": [
								[
									250,
									251
								],
								[
									null,
									"Horde_Smtp_Exception_Recipients"
								]
							]
						},
						{
							"file": "/var/www/html/custom_apps/mail/vendor/bytestream/horde-mail/lib/Horde/Mail/Transport/Smtphorde.php",
							"line": 143,
							"function": "send",
							"class": "Horde_Smtp",
							"type": "->",
							"args": [
								[
									"Horde_Mail_Rfc822_Address",
									[],
									"christian.hartmann"
								],
								[
									"Horde_Mail_Rfc822_List"
								],
								null
							]
						},
						{
							"file": "/var/www/html/custom_apps/mail/vendor/bytestream/horde-mime/lib/Horde/Mime/Part.php",
							"line": 1620,
							"function": "send",
							"class": "Horde_Mail_Transport_Smtphorde",
							"type": "->",
							"args": [
								"recipient.address@domain",
								[
									"Christian Hartmann <sender.address@domain>",
									"recipient.address@domain",
									"",
									"Test",
									"<20240326125355.Horde.eC1lnQkQQ6-5alzMo3hzVZc@cloud.domain.tld>",
									"And 5 more entries, set log level to debug to see all entries"
								],
								null
							]
						},
						{
							"file": "/var/www/html/custom_apps/mail/vendor/bytestream/horde-mime/lib/Horde/Mime/Mail.php",
							"line": 479,
							"function": "send",
							"class": "Horde_Mime_Part",
							"type": "->",
							"args": [
								"recipient.address@domain",
								[
									"Horde_Mime_Headers"
								],
								[
									"Horde_Mail_Transport_Smtphorde",
									"\r\n",
									false
								]
							]
						},
						{
							"file": "/var/www/html/custom_apps/mail/lib/Service/MailTransmission.php",
							"line": 271,
							"function": "send",
							"class": "Horde_Mime_Mail",
							"type": "->",
							"args": [
								[
									"Horde_Mail_Transport_Smtphorde",
									"\r\n",
									false
								],
								false,
								false
							]
						},
						{
							"file": "/var/www/html/custom_apps/mail/lib/Service/MailTransmission.php",
							"line": 343,
							"function": "sendMessage",
							"class": "OCA\\Mail\\Service\\MailTransmission",
							"type": "->",
							"args": [
								[
									"OCA\\Mail\\Model\\NewMessageData"
								],
								null,
								null
							]
						},
						{
							"file": "/var/www/html/custom_apps/mail/lib/Service/OutboxService.php",
							"line": 142,
							"function": "sendLocalMessage",
							"class": "OCA\\Mail\\Service\\MailTransmission",
							"type": "->",
							"args": [
								[
									"OCA\\Mail\\Account"
								],
								[
									"OCA\\Mail\\Db\\LocalMessage",
									979
								]
							]
						},
						{
							"file": "/var/www/html/custom_apps/mail/lib/Controller/OutboxController.php",
							"line": 247,
							"function": "sendMessage",
							"class": "OCA\\Mail\\Service\\OutboxService",
							"type": "->",
							"args": [
								[
									"OCA\\Mail\\Db\\LocalMessage",
									979
								],
								[
									"OCA\\Mail\\Account"
								]
							]
						},
						{
							"file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
							"line": 230,
							"function": "send",
							"class": "OCA\\Mail\\Controller\\OutboxController",
							"type": "->",
							"args": [
								979
							]
						},
						{
							"file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
							"line": 137,
							"function": "executeController",
							"class": "OC\\AppFramework\\Http\\Dispatcher",
							"type": "->",
							"args": [
								[
									"OCA\\Mail\\Controller\\OutboxController"
								],
								"send"
							]
						},
						{
							"file": "/var/www/html/lib/private/AppFramework/App.php",
							"line": 184,
							"function": "dispatch",
							"class": "OC\\AppFramework\\Http\\Dispatcher",
							"type": "->",
							"args": [
								[
									"OCA\\Mail\\Controller\\OutboxController"
								],
								"send"
							]
						},
						{
							"file": "/var/www/html/lib/private/Route/Router.php",
							"line": 315,
							"function": "main",
							"class": "OC\\AppFramework\\App",
							"type": "::",
							"args": [
								"OCA\\Mail\\Controller\\OutboxController",
								"send",
								[
									"OC\\AppFramework\\DependencyInjection\\DIContainer"
								],
								[
									"979",
									"mail.outbox.send"
								]
							]
						},
						{
							"file": "/var/www/html/lib/base.php",
							"line": 1069,
							"function": "match",
							"class": "OC\\Route\\Router",
							"type": "->",
							"args": [
								"/apps/mail/api/outbox/979"
							]
						},
						{
							"file": "/var/www/html/index.php",
							"line": 39,
							"function": "handleRequest",
							"class": "OC",
							"type": "::",
							"args": []
						}
					],
					"File": "/var/www/html/custom_apps/mail/vendor/nextcloud/horde-smtp/lib/Horde/Smtp.php",
					"Line": 1076
				}
			}
		},
		"message": "Could not send message: Message could not be delivered - the address was not found, is unknown, or is not receiving messages.",
		"exception": [],
		"CustomMessage": "Could not send message: Message could not be delivered - the address was not found, is unknown, or is not receiving messages."
	},
	"id": "6602c6297cd8c"
}

Browser console only shows an error 500 with no specific error message at all

This problem is especially confusing for users if they use a contact group as recipient and one of the addresses in this group is no longer existent on the server.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in custom_apps/mail/lib/Service/MailTransmission.php around lines 271-343, then follow the failure through OutboxService.php and OutboxController.php. Reproduce the non-existent-recipient SMTP error and inspect how its message reaches the client. Done means the sending failure shown to the user includes a useful reason rather than only a generic error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.