Smtp relay incompatible with mail forward

,

Hi all,

I’ve recently discovered something quite annoying with the use of Smtp relay (Mailjet).
When I setup a Mail forward for a user of my Yunohost instance, this mail forward will only partly work.

  • If an email is received from an email from the instance, it will be correctly forwarded
  • If an email is received from an external email domain, it will be received correctly but not forwarded

It seems that this is because the forwarded email from an external email domain is seen by the relay as a stranger domain, for which the relay has no authorization to send.

For example, if I setup email@mydomain.fr to forward to email@gmail.com. If I receive an email from myfriend@yahoo.fr, then my smtp relay will tell me that I have tried to send from the unauthorized email myfriend@yahoo.fr

Do you have the same issue ? Would you know how to solve it ?

Thanks in advance for your help !

For those who would be interested, the best solution I could find so far :

  1. Edit /etc/dovecot/dovecot.conf
  2. Activate editheader sieve plugin by adding
plugin {
  # Use editheader
  sieve_extensions = +editheader
}
  1. Relaunch Dovecot service
  2. Use rainloop to create a new raw sieve filter
require ["copy","editheader","variables"];
# rule:[Redirect]
if true # for all emails - but you can change that part
{
    # Match the From header field ...
    if header :matches "From" "*" {
        set "from" "${1}";
    }
    # Match the Subject field ...
    if header :matches "Subject" "*" {
        set "subject" "${1}";
    }
        # Delete the Subject
        deleteheader :contains "Subject";
        # Recreate the subject and add the sender info
        addheader :last "Subject" "[Redirect from ${from}] ${subject}";
        # Make sure that external email will be able to reply to the right person
        addheader "Reply-To" "${from}";
        # Delete the sender
        deleteheader :contains "From";
        # Replace the sender by the Yunohost receiver email
        # This will trick the SMTP relay provider
        addheader "From" "youremail@yourinstance.fr";
        # Forward a copy to external email
        redirect :copy "email@external.fr";
}

This works very well. Only compromise is that the external email will receive the email as being sent from youremail@yourinstance.fr instead of the sender.
In my opinion a small compromise that makes available the safety and good receivability of using an external SMTP relay !

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.