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

Bug report: empty smtp.mailfrom on Delivery Status Notification (DSN) #629

Open
1 task done
oliverpool opened this issue Sep 13, 2023 · 5 comments
Open
1 task done
Labels
bug Something isn't working. ready-for-release Feature is implemented and available for testing in dev branch. It will be included in the next rele

Comments

@oliverpool
Copy link

oliverpool commented Sep 13, 2023

Describe the bug

I am using maddy as a send-only SMTP server and it works great, thank you so much for this nice piece of software !

I want set up Delivery Status Notification to my inbox. However they are marked a spam by my email hosting (which has nothing to do with maddy) because the the lack of the mailfrom: spf=none smtp.mailfrom="" smtp.helo=maddy.example.org (I was able to add dkim signing though).

Steps to reproduce

Setup a bounce with a remote MX sending and trigger a bounce message:

Configuration file

target.queue remote_queue {
    target &outbound_delivery

    autogenerated_msg_domain $(primary_domain)
    bounce {
        destination $(local_domains) {
            modify {
                dkim {
                    domains $(local_domains)
                    selector key
                    key_path dkim-keys/{selector}.key
                }
            }
            deliver_to &outbound_delivery
        }
        default_destination {
            reject 550 5.0.0 "Refusing to send DSNs to non-local addresses"
        }
    }
}

Environment information

  • maddy version: 0.7.0

Relevant code

The last argument of dsnDelivery, err := q.dsnPipeline.Start(mailCtx, dsnMeta, "") is always empty.

dsnDelivery, err := q.dsnPipeline.Start(mailCtx, dsnMeta, "")

Is there any reason this is not set to dsnEnvelope.From (which is set to "MAILER-DAEMON@" + q.autogenMsgDomain) ?
If yes, would you consider an option to set it in some cases? Or is there a configuration option that I am missing?

  • I'm willing to help with the implementation
@oliverpool oliverpool added the bug Something isn't working. label Sep 13, 2023
@foxcpp
Copy link
Owner

foxcpp commented Dec 21, 2023

RFC 5321 (SMTP spec) requires (a "MUST") all delivery status notifications to be sent with an empty MAIL FROM: https://datatracker.ietf.org/doc/html/rfc5321#section-3.6.3

Of course, SMTP servers MUST NOT send notification
messages about problems transporting notification messages. One way
to prevent loops in error reporting is to specify a null reverse-path
in the MAIL command of a notification message. When such a message
is transmitted, the reverse-path MUST be set to null (see
Section 4.5.5 for additional discussion).

@foxcpp
Copy link
Owner

foxcpp commented Dec 21, 2023

Though, you can "hack" it and rewrite MAIL FROM using modify.replace_rcpt:

modify {
  replace_rcpt static {
    entry "" "[email protected]"
  }
}

Since the problem mentioned in the RFC does not apply to your usecase, it probably will be fine.

@foxcpp foxcpp closed this as completed Jan 21, 2024
@foxcpp foxcpp added the invalid Not enough information to troubleshoot or can't reproduce. label Jan 21, 2024
@lukastribus
Copy link

I have the same need, and I'm really struggling with this.

The debug output doesn't show the actual from used; I tried both replace_rcpt and replace_sender, before and after destination $(local_domains).

I tried static and regexp replacements, but none of it seems to work.

In most configurations I just get a:

failed to enqueue DSN {[...],"reason":"malformed address: address: missing at-sign"}

Can someone post an entire target.queue remote_queue section with this configuration?

@foxcpp
Copy link
Owner

foxcpp commented Feb 8, 2024

Apparently, replace_* apply normalization functions to addresses and it does not allow "", hence the error.

Pushed cee5777 to master that allows this.

@foxcpp foxcpp added ready-for-release Feature is implemented and available for testing in dev branch. It will be included in the next rele and removed invalid Not enough information to troubleshoot or can't reproduce. labels Feb 8, 2024
@lukastribus
Copy link

Thank you, with cee5777 this now works as expected:

target.queue remote_queue {
    target &outbound_delivery

    autogenerated_msg_domain $(primary_domain)
    bounce {
        modify {
                replace_sender static { entry "" "[email protected]" }
        }
        destination $(local_domains) {
            modify {
                dkim $(primary_domain) $(local_domains) <YOUR-DKIM-SELECTOR>
            }

            deliver_to &remote_queue

        }
        default_destination {
            reject 550 5.0.0 "Refusing to send DSNs to non-local addresses"
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. ready-for-release Feature is implemented and available for testing in dev branch. It will be included in the next rele
Projects
None yet
Development

No branches or pull requests

3 participants