znuny / Znuny

Znuny/Znuny LTS is a fork of the ((OTRS)) Community Edition, one of the most flexible web-based ticketing systems used for Customer Service, Help Desk, IT Service Management.
https://www.znuny.org
GNU General Public License v3.0
386 stars 89 forks source link

Bug - SendmailNotificationEnvelopeFrom config parameter has no effect in email From header #491

Open samueldc opened 1 year ago

samueldc commented 1 year ago

Environment

Expected behaviour

SendmailNotificationEnvelopeFrom config parameter should change the From header of notification messages.

Actual behaviour

SendmailNotificationEnvelopeFrom has no effect in the From header because the header section is formed before SendmailNotificationEnvelopeFrom config parameter check. And after that the header section is not adjusted (I suggest a regex substitution). SendmailNotificationEnvelopeFrom is only used in the $smtp->mail method with no effect in the actual message.

Kernel::System::Email::636 (version 7.0):

    # Save it to the queue
    my $MailQueueObject = $Kernel::OM->Get('Kernel::System::MailQueue');
    my $MailQueued      = $MailQueueObject->Create(
        ArticleID => $Param{ArticleID},
        MessageID => $Param{'Message-ID'},
        Sender    => $RealFrom, ======> New From is here! <======
        Recipient => \@ToArray,
        Message   => {
            Header => $Param{Header}, ======> But the header is already using another From <======
            Body   => $Param{Body},
        },
        CommunicationLogObject => $CommunicationLogObject,
    );

Kernel::System::Email:SMTP::307 (version 7.0):

    # set envelope from, return if from was not accepted by the server
    if ( !$SMTP->( 'mail', $Param{From}, ) ) { ======> New From is only used here with no effect at all <======

        my $FullErrorMessage = sprintf(
            "Envelope from '%s' not accepted by the server: %s, %s!",
            $Param{From},
            $SMTP->( 'code', ),
            $SMTP->( 'message', ),
        );

        $Param{CommunicationLogObject}->ObjectLog(
            ObjectLogType => 'Message',
            Priority      => 'Error',
            Key           => 'Kernel::System::Email::' . $Self->{EmailModuleName},
            Value         => $FullErrorMessage,
        );

        return $Self->_SendError(
            %Param,
            ErrorMessage => $FullErrorMessage,
            SMTP         => $SMTP,
        );
    }

How to reproduce

Steps to reproduce the behavior:

  1. Change SendmailNotificationEnvelopeFrom to an email address different from the main email address or from the queue email address.
  2. Trigger a notification.
  3. Check the email message and headers.
  4. See there is no effect.
samueldc commented 1 year ago

I'm not a SMPT header specialist, but suggest the following code after $RealFrom definition, but right before saving the message to the queue:

    # adjust from header with real from
    $Param{Header} =~ s{(\X*?From: \X+?<).+?(>\X+)}{$1$RealFrom$2}img;
KaiHerlemann commented 1 year ago

Hi @samueldc

the "From" header is not set by the SendmailNotificationEnvelopeFrom setting. The purpose of this setting is to set the "Envelope From" header. The From header of a notification is set by the NotificationSenderEmail setting.

So please use this setting, then it should be fine.

Kai

samueldc commented 1 year ago

Hi @KaiHerlemann Thanks for replying. Already tried NotificationSenderEmail. It's not working also.

samueldc commented 1 year ago

The only pertinent reference to the NotificationSenderEmail configuration parameter occurs within the Kernel::System::Ticket::Event::NotificationEvent::Transport::Email class when the recipient type is set to 'Agent'.

When the recipient type is 'Customer,' the NotificationSenderEmail parameter appears to have no effect.

Although this behavior is not clearly stated in the parameter's description, in my opinion, the use case for this configuration parameter would be more logical if it were applicable when the recipient type is 'Customer'.

KaiHerlemann commented 1 year ago

It's true that the setting is not relevant when notifications go to the customer user. (I didn't know this issue is about notifications to customers and not agents.)

If a reply, outgoing email or ticket notification is sent to the customer user, the "From" address is always the system address of the queue. In those cases, neither the NotificationSenderEmail nor SendmailNotificationEnvelopeFrom setting is relevant. There is one exception, for auto-responses it's the system address, which is set in the auto-response settings.