Forwarding emails | MDaemon Technologies, Ltd.

Forwarding emails


  • Hello everyone!, I have such a task, there is a mailbox that receives mail info@domain.com and there is a large list of people who need to forward these letters that come there, is there a way for the mail server to take a list of addresses from a text file, since in the GUI in the settings of the mailbox info@domain.com there are restrictions and this is inconvenient. the number of boxes for forwarding is about 30, this list of external boxes such as Google Yahoo and others is important

    I looked to see if it is possible to create processing through a content filter



  • The forwarding field is currently limited to 512 characters.  

    Have you considered creating a mailing list instead of trying to forward messages sent to a mailbox to 30 addresses?  You'd just need to add the 30 addresses to the list as members.  

    Another option would be to use aliases in the forwarding field.  For example, you would configure the account to forward to a@a.com, b@a.com, c@a.com.  Then go to Main | Aliases | Settings, check the box for "Its OK to relay mail for aliases that include foreign domains".

    Then create an aliases for:

    a@a.com = actualuser@externaldomain.com
    b@a.com = anotheruser@anotherdomain.com
    c@a.com = user549838@gmail.com

    You would need an alias for each address you want to forward the mail to.

    The last option would be to use a powershell script and have the content filter run it.  This is the most complicated setup as you'll a script.  I don't have one already done, but it could be written.  If you are interested in powershell let me know and I'll see what I can come up with.  With a powershell script you'd have to maintain the list of addresses to forward to in the script.  If you are not comfortable editing a script, this is probably not the option for you.


  • so far I have found a way, from the main info box there is a mailing to other boxes where the boxes for sending are registered, this is a crutch, regarding the script, this is interesting, I would like to see, and what process is engaged in processing and sending the letter?


  • so far I have found a way, from the main info box there is a mailing to other boxes where the boxes for sending are registered, this is a crutch

    Are you saying the issue with mailing lists is that each member can send to the list and cause an email to be sent ot every member of the list?  You can prevent this by making the members of the mailing list read only.  Main | Mailing List Manager | Select the lsit | Edit | Select a Member | Edit, select the read only radio button in the Type section.

    Or are you saying that the problem with a mailing list is that the senders need to be members of the list in order to send to a list?  You can fix this by unchecking the box for "Refuse messages from non list members" (Main | Mailing List Manager | Select the list | Edit | Settings

    regarding the script, this is interesting, I would like to see, and what process is engaged in processing and sending the letter?

    It depends on what language the script is written in.  If you write the script in Powershell, it will be ran by powershell.exe.  Here is an example content filter rule that runs a powershell script:

    RuleName=Test Powershell Script
    Enable=Yes
    ThisRuleCondition=All
    ProcessQueue=BOTH
    Condition01=X-MDAEMON-DELIVER-TO|contains|AND|user@domain.com|
    Action01=run a program|"-1,0,0","C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File c:\scripts\test.ps1 -MSGFileName $MESSAGEFILENAME$"

     

     


  •  

    Are you saying the issue with mailing lists is that each member can send to the list and cause an email to be sent ot every member of the list?  You can prevent this by making the members of the mailing list read only.  Main | Mailing List Manager | Select the lsit | Edit | Select a Member | Edit, select the read only radio button in the Type section.

    Or are you saying that the problem with a mailing list is that the senders need to be members of the list in order to send to a list?  You can fix this by unchecking the box for "Refuse messages from non list members" (Main | Mailing List Manager | Select the list | Edit | Settings

    participants are not on the server list, they are deleted

    RuleName=Test Powershell Script
    Enable=Yes
    ThisRuleCondition=All
    ProcessQueue=BOTH
    Condition01=X-MDAEMON-DELIVER-TO|contains|AND|user@domain.com|
    Action01=run a program|"-1,0,0","C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File c:\scripts\test.ps1 -MSGFileName $MESSAGEFILENAME$"

    is there an example of a message forwarding script?


  • participants are not on the server list, they are deleted

    I'm not sure what you mean, can you elaborate.  Can you post a log snippet that shows the issue happening? Any email address can be a member of a mailing list in MDaemon it is not limited to local users.   If the members of the list are being automatically removed from the list, turn off the options for Remove underliverable email addresses from list membership.  (Main | Mailing List Manager | Select the list | Edit | Settings)

    If you are having issues with list messages bouncing because they are sent using a NULL return path, go to Main | Mailing List Manager | Select the list | Edit | Notifications and enter a valid local address in the field for "List's SMTP Bounce Address"

    is there an example of a message forwarding script?

    I do not have a script that forwards messages.  I'll see if I can figure something out for you, but I don't think its going to be a simple script.

     

     


  • I wrote a script that will forward messages to as many recipients as you'd like.  I have only done basic testing, so there may be issues. Please thoroughly test it before implementing in a production environment.

    This script will not forward to a combination of local and remote recipients.  It will do one or the other. 

    The script allows the original message to be delivered to the mailbox.

    The script is searching and replacing headers in the email message.  If there are strings that match the headers in any part of the message, including the message body, they will be replaced.  For example, if the body has "X-Return-Path:" in it, it will be replaced with "X-Return-Path: <$OriginalRecipient>"   It does not decode message content, if the body of the message is encoded it will not match.

    param(
        [string]$MSGFileName
    )
    
    ################################################################################################################################
    ################################################################################################################################
    ## Forward message to lots of people v 1.0.0                                                                                  ##
    ## May 14 2025	     	     												                                                  ##
    ## Copyright MDaemon Technologies	2025											                                          ##
    ## 	                                                                                                                          ##
    ## This script is designed to be ran by the content filter in MDaemon. It accepts the path to a message file as a parameter.  ##
    ## The script creates a copy of the message for each recipient in the $Recipients variable and places it in the remote queue. ##
    ##                                                                                                                            ##
    ## You can forward to all local users by changing the $RemoteQ variable to point to the local queue.  This script is not      ##
    ## designed to forward to a combination of local and remote recipients.                                                       ##
    ##                                                                                                                            ##
    ## This script may cause issues if messages that it is processing contain emails as attachment or email headers in the body   ##
    ## of the messages.                                                                                                           ##
    ##                                                                                                                            ##
    ## Here is a sample content filter rule that can be used to call the script:                                                  ##
    ##                                                                                                                            ##
    ##  RuleName=Forward messages sent to user@localdomain.com                                                                    ##
    ##  Enable=Yes                                                                                                                ##
    ##  ThisRuleCondition=All                                                                                                     ##
    ##  ProcessQueue=LOCAL                                                                                                        ##
    ##  Condition01=X-MDAEMON-DELIVER-TO|contains|AND|user@localdomain.com|                                                       ##
    ##  Action01=run a program|"-1,0,0","C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass        ##
    ##        c:\mdaemon\PowerShell\ForwardtoLotsofEmails.ps1 -MSGFileName "$MESSAGEFILENAME$""                                              ##
    ##                                                                                                                            ##
    ##                                                                                                                            ##
    ##                                                                                                                            ##
    ## MDaemon Technologies offers no warranty, provides no support, and is not responsible for any damages that may be arise     ##
    ## from the use of this script. Use at your own risk.                                                                         ##
    ##                                                                                                                            ##
    ################################################################################################################################
    ################################################################################################################################
    
    
    #Set these variables to the correct values!!
    $Recipients = ("user1@externaldomain.com","user2@otherexternaldomain.com")
    $OriginalRecipient = "user@localdomain.com"
    $RemoteQ = "c:\mdaemon\queues\Remote\"
    
    
    $FileName = Split-Path $MSGFileName -leaf
    
    $AttachmentFileNameWOExtension = [System.IO.Path]::GetFileNameWithoutExtension($FileName)
    $AttachmentFileNameExtension = [System.IO.Path]::GetExtension($FileName)
    
    [bigint]$FileNumber = $AttachmentFileNameWOExtension -replace "[^0-9]" , ""
    
    $RemoteQueueFilePath = Join-Path $RemoteQ $FileName
    
    $newLines = @("X-MDRedirect: 1",
        "X-MDRedirect_From: $OriginalRecipient"
    )
    
    $existingContent = Get-Content $MSGFileName
    $combinedContent = $newLines + $existingContent
    
    ForEach ($Recipient in $Recipients){
    
        $combinedContent = $combinedContent -replace "X-MDaemon-Deliver-To: $OriginalRecipient", "X-MDaemon-Deliver-To: $Recipient"
        $combinedContent = $combinedContent -replace "X-Return-Path:.*", "X-Return-Path: <$OriginalRecipient>"
    
        While(Test-Path $RemoteQueueFilePath){
        
            $FileNumber += 1
            $NewFileName = "pd" + $FileNumber + $AttachmentFileNameExtension
    
            $RemoteQueueFilePath = Join-Path $RemoteQ $NewFileName
    
            
        }      
    
        Write-Host "RemoteQ Path: $RemoteQueueFilePath"    
        Set-Content $combinedContent -Path $RemoteQueueFilePath
    }
    
    

Please login to reply this topic!