How to set Getmail to be used with several RCs

Following the previous explanation about how to use Getmail with an External MDA, I will share a way to surpass the limitations on Getmail to handle several RCs at once, like I have done in my Smart Host.

All this procedure was done in one MacOS Maverick 10.9.5, and is still working after 2 years ago from the date of this post.

I will start from how you can add users RC’s and then I will explain how can you download mail and redirect it to an External MDA. There are other ways to do this, and maybe better, but this was the way that I have done with the time that I had. In any bold text in further quotes, is where you must edit before installing it.

So to avoid having to create each RC by hand, I have created one script in bash to do that for me, with just one input, the name of the user that I pretend to add, who is:

#!/bin/bash

echo “::Creating new user account for Mail::”
echo “NOTE: Dont forget to run as root”
echo “”
name1=”qwe”
name2=”asd”
domain=”email_domain
while [ “$name1” != “$name2” ]; do
echo “Username(e.g. <username>@<domain>): ”
read name1
echo “Confirm username(e.g. <username>@<domain>): ”
read name2
if [ “$name1” != “$name2” ]; then
echo “Usernames doesnt match”
else
echo “Usernames match”
username=$name1
fi
echo “”
done

#default password to connect our local account to our external account at remote mail server
def_pw=”use_a_strong_password_with_random_characters

#location=”$(pwd)”
#echo “${location}”

###To send###

#Per-sender authentication
cd /Library/Server/Mail/Config/postfix/sasl
#add line per user at an existing file passwd
echo “$username@$domain $username@$domain:$def_pw” >> passwd
postmap passwd

###To receive###
cd /Users/x-server/.getmail/
#create file for user and add the first line
echo “[retriever]” > getmailrc_$username
echo “type = SimplePOP3SSLRetriever” >> getmailrc_$username
echo “server = cpanel.mailprovider.pt” >> getmailrc_$username
echo “port: 995” >> getmailrc_$username
echo “username = $username@mailprovider.pt” >> getmailrc_$username
echo “password = $def_pw” >> getmailrc_$username
echo “” >> getmailrc_$username
echo “[destination]” >> getmailrc_$username
echo “type = MDA_external” >> getmailrc_$username
echo “path = /usr/sbin/sendmail” >> getmailrc_$username
echo “arguments = (‘-bm’, ‘$username’)” >> getmailrc_$username
echo “unixfrom = true” >> getmailrc_$username
echo “” >> getmailrc_$username
echo “[options]” >> getmailrc_$username
echo “delete = true” >> getmailrc_$username
echo “message_log = ~/.getmail/logs/getmailrc_$username.log” >> getmailrc_$username

###Reload postfix###
postfix reload

echo “User $username added to send and receive mail externally!”

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s