Hi there,
I have found that even my local emails are being sent out of my server and then are routed back to this domain, how can I route emails locally for my domain [example.com] to reside on the same server and the attachments if any are not duplicated either in this case are rather shared through "symbolic links".
If someone can share a Script for WHM to route emails locally for the same domain, that will be great. I did try this script but failed on two accounts
I will appreciate any assistance to get this resolved.
Thanks and Regards,
I have found that even my local emails are being sent out of my server and then are routed back to this domain, how can I route emails locally for my domain [example.com] to reside on the same server and the attachments if any are not duplicated either in this case are rather shared through "symbolic links".
If someone can share a Script for WHM to route emails locally for the same domain, that will be great. I did try this script but failed on two accounts
- it failed to fetch 'dig' command failed to fetch any MX record [even though when executed directly, it succeeds]
- I am using CentOS v7.9.2009 STANDARD cPanel v110.0.2, and I don't find any `postfix` folder under `/etc` or even `main.cf` file for that matter.
#!/bin/bash
# Add your domain name belowdomain="example.com"# Retrieve the local mail exchanger (MX) records for the domainmx_records=$(dig +short MX $domain | awk '{print $2}' | sort -n)# Create an array to store the local mail exchangerslocal_mx=()# Loop through each MX record and check if it points to the local serverfor mx in $mx_recordsdoif [[ $mx == "$(hostname -f)" ]]; thenlocal_mx+=($mx)fidone# Check if there are any local mail exchangersif [ ${#local_mx[@]} -eq 0 ]; thenecho "No local mail exchangers found for $domain."exit 1fi# Create a Postfix transport map filetransport_file="/etc/postfix/transport"# Create or overwrite the transport map fileecho "$domain local:${local_mx[0]}" > $transport_file# Update the transport mappostmap $transport_file# Configure Postfix to use Maildir format and create symbolic links for attachmentsmain_cf="/etc/postfix/main.cf"attachments_dir="/var/mail/attachments"# Add or update the configuration in main.cfecho "# Configure Postfix to use Maildir format and symbolic links for attachmentshome_mailbox = Maildir/maildir_copy = nomime_directory = $attachments_dir" >> $main_cf# Create the attachments directorymkdir -p $attachments_dir# Set permissions for the attachments directorychown -R postfix:postfix $attachments_dir# Restart the Postfix serviceservice postfix restartecho "Email routing for $domain has been configured to route locally."echo "Attachments will be shared using symbolic links."
`I will appreciate any assistance to get this resolved.
Thanks and Regards,
Last edited by a moderator: