rnwood / smtp4dev

smtp4dev - the fake smtp email server for development and testing
BSD 3-Clause "New" or "Revised" License
2.97k stars 334 forks source link

NullReferenceException during Auto-Relay #1438

Closed sodermatt closed 3 months ago

sodermatt commented 3 months ago

I'm trying to get the Auto-Relay-Feature running.

I configured the following RelayOptions (Mail-Addresses, Server-Name are replaced with dummy-values)

`"RelayOptions": {

"IsEnabled": true, "SmtpServer": "mail.domain.de", "SmtpPort": 25, "TlsMode": "Auto", "AutomaticEmails": ["xyz@domain.de"], "AutomaticRelayExpression": "recipient.match(/xyz@domain.de$/)", "SenderAddress": "", "Login": "", "Password": "" },`

When I submit a "Send-MailMessage"-PS, the mail is successfully delivered to smtp4dev, but the Auto-Relay throws an error.

Output in cmd-Window:

Session started. Client address ::1. Message received. Client address ::1, From abc@domain.de, To xyz@domain.de, SecureConnection: False. Processing received message AutomaticRelayExpression: (message: {message.Id}, recipient: 23cdcf12-29df-4f89-bc4e-700694f50291, session: {session.Id}) => xyz@domain.de => 04de849a-bf01-4745-81ca-660f90e887cd Relaying message to xyz@domain.de Can not relay message to xyz@domain.de: System.NullReferenceException: Object reference not set to an instance of an object. at Rnwood.Smtp4dev.Server.Smtp4devServer.TryRelayMessage(Message message, MailboxAddress[] overrideRecipients) in D:\a\1\s\Rnwood.Smtp4dev\Server\Smtp4devServer.cs:line 407 System.NullReferenceException: Object reference not set to an instance of an object. at Rnwood.Smtp4dev.Server.Smtp4devServer.TryRelayMessage(Message message, MailboxAddress[] overrideRecipients) in D:\a\1\s\Rnwood.Smtp4dev\Server\Smtp4devServer.cs:line 407 Processing received message DONE Session completed. Client address ::1. Number of messages 1.

Am I missing a Config-Option?

rnwood commented 3 months ago

It's the 23cdcf12-29df-4f89-bc4e-700694f50291 that's looking strange here. Can you work out where that's coming from?


From: sodermatt @.> Sent: Friday, April 26, 2024 4:04:01 PM To: rnwood/smtp4dev @.> Cc: Subscribed @.***> Subject: [rnwood/smtp4dev] NullReferenceException during Auto-Relay (Issue #1438)

I'm trying to get the Auto.Relay-Feature running.

I configured the following RealyOptions (Mail-Addresses, Server-Name are replaced with dummy-values)

`"RelayOptions": {

"IsEnabled": true, "SmtpServer": "mail.domain.de", "SmtpPort": 25, "TlsMode": "Auto", "AutomaticEmails": @.**@.>"], "AutomaticRelayExpression": @.**@.>$/)", "SenderAddress": "", "Login": "", "Password": "" },`

When I submit a "Send-MailMessage"-PS, the mail is successfully delivered to smtp4dev, but the Auto-Relay throws an error.

Output in cmd-Window:

Session started. Client address ::1. Message received. Client address ::1, From @., To @., SecureConnection: False. Processing received message AutomaticRelayExpression: (message: {message.Id}, recipient: 23cdcf12-29df-4f89-bc4e-700694f50291, session: {session.Id}) => @. => 04de849a-bf01-4745-81ca-660f90e887cd Relaying message to @. Can not relay message to @.***: System.NullReferenceException: Object reference not set to an instance of an object. at Rnwood.Smtp4dev.Server.Smtp4devServer.TryRelayMessage(Message message, MailboxAddress[] overrideRecipients) in D:\a\1\s\Rnwood.Smtp4dev\Server\Smtp4devServer.cs:line 407 System.NullReferenceException: Object reference not set to an instance of an object. at Rnwood.Smtp4dev.Server.Smtp4devServer.TryRelayMessage(Message message, MailboxAddress[] overrideRecipients) in D:\a\1\s\Rnwood.Smtp4dev\Server\Smtp4devServer.cs:line 407 Processing received message DONE Session completed. Client address ::1. Number of messages 1.

Am I missing a Config-Option?

— Reply to this email directly, view it on GitHubhttps://github.com/rnwood/smtp4dev/issues/1438, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAKEGF6DKHSGIDPPF3EUUH3Y7JUGDAVCNFSM6AAAAABG26HG4CVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI3DKOJXHE2DMNQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

rnwood commented 3 months ago

You can ignore that question. I am able to reproduce and will resolve this.

The ID is because there is a bug in the logging. It's the message ID.

rnwood commented 3 months ago

Should be resolved by the PR.

Note that AutomaticEmails and the result of AutomaticRelayExpression will both apply are combined and the message is relayed to the distinct results for each origiinal recpient. So you don't need to configure both to match the same addresses. I guess you already know this and you're just testing?

sodermatt commented 3 months ago

So you don't need to configure both to match the same addresses. I guess you already know this and you're just testing?

Correct, this was just a test configuration - thanks for reacting this fast, really appreciated! Will test as soon as build is done