# Howto: Virtualmail with Sendmail plus virtualusers connecting to courier-imap.



## paulfrottawa (Oct 19, 2012)

I'll set this up in a jail and I will need to write into /usr/libexec/sm.bin folder (man smrsh). So in /etc/fstab you will need rw for this jail. 
example

```
/home/j/mroot   /home/j/mx2    nullfs  rw  0   0
```

Inside Jail:

```
echo '192.168.0.1 mail.columbiangold.ca' >> /etc/hosts
```

Configuring sendmail:
/etc/mail/virtusertable

```
test@columbiangold.ca user1.virtual
paul@columbiangold.ca user2.virtual
@columbiangold.ca user2.virtual
```
/etc/mail/aliases (I placed this at the bottom of the file.)

```
user1.virtual: |/usr/libexec/sm.bin/user1.virtual
user2.virtual: |/usr/libexec/sm.bin/user2.virtual
```

/etc/mail/local-host-names

```
columbiangold.ca
mail.columbiangold.ca
```

/etc/mail/access

```
192.168.0.1                          RELAY
```



change directory to /etc/mail

```
make
```

Install procmail

```
portmaster mail/procmail
```


/etc/mail/mail.columbiangold.ca.mc
add procmail above: MAILER(local)

```
FEATURE(`local_procmail', `/usr/local/bin/procmail -t -Y -a $h -d $u')
MAILER(local)
MAILER(smtp)
```


change to directory /etc/mail and again do this.

```
newaliases
make
```

/usr/libexec/sm.bin/user1.virtual  

```
/usr/local/bin/procmail /usr/local/etc/procmailrcs/user1.virtual
```

/usr/libexec/sm.bin/user2.virtual

```
/usr/local/bin/procmail /usr/local/etc/procmailrcs/user2.virtual
```

/usr/local/etc/procmailrcs/user2.virtual

```
PATH=/bin:/usr/bin:/usr/local/bin
MONTHYEAR=^Date +%y%m
VHOME=/home/mail/domains/columbiangold/mail/paul
LOGFILE=/home/mail/domains/columbiangold/logs/user2.virtual/log
LOGABSTRACT=all
VERBOSE=on
# Spam filter
:0fw
| /usr/local/bin/spamc

:0:
* ^X-Spam-Status: Yes
$VHOME/spam


:0:
$VHOME/inbox/
```

Install p5-Mail-SpamAssassin & add SPF_QUERY support


```
portmaster mail/p5-Mail-SpamAssassin
```

Continued ---->>>>> next post


----------



## paulfrottawa (Oct 19, 2012)

```
install -v -m 0764 -o mailnull -d /home/mail/domains/columbiangold/mail/test
install -v -m 0764 -o mailnull -d /home/mail/domains/columbiangold/mail/paul
install -m 0700 -o mailnull -d /home/mail/domains/columbiangold/logs/user2.virtual
install -m 0700 -o mailnull -d /home/mail/domains/columbiangold/logs/user1.virtual
```


Install courier-imap & select AUTH_USERDB

```
portmaster mail/courier-imap
```

After imap is installed run

```
pw2userdb
```
and copy your user info's 2 lines:

```
mailnull	uid=26|gid=26|home=/var/spool/mqueue|shell=/usr/sbin/nologin|systempw=*|gecos=Sendmail Default User
26=	mailnull
```
and copy to this file:

```
mkdir /usr/local/etc/userdb
vi /usr/local/etc/userdb/default
```


```
makeuserdb
```
/usr/local/etc/authlib/authdaemonrc change authmodulelist=
this will avoid syslog messages.


```
authmodulelist="authuserdb"
```

/etc/rc.conf

```
spamd_enable="YES"
spamd_flags="-A 192.168.0.1 -u spamd -H /var/spool/spamd"
courier_imap_imapd_ssl_enable="YES"
courier_imap_imapd_enable="YES"
courier_authdaemond_enable="YES"
```

change permissions to quell authdaemond err. and start authdaemond

```
chmod 0700 /usr/local/etc/userdb
/usr/local/etc/rc.d/courier-authdaemond start
```

now run authenumerate to place text in a file. and add a home path for mailnull inline to the virtual mail directories. Notice every textgroup has a tab spacing.

```
authenumerate -s > /usr/local/etc/courier-imap/shared/index
vi /usr/local/etc/courier-imap/shared/index
mailnull        26      26      /home/mail/domains
```

Continued --->> next post


----------



## paulfrottawa (Oct 19, 2012)

man userdb  (order and the no last foward "/" execpt specifying the Maildir 'like so here and in procmailrcs/columbiangold file')

```
userdb columbiangold/paul@columbiangold.ca set home=/home/mail/domains/columbiangold/mail/paul mail=/home/mail/domains/columbiangold/mail/paul/inbox/ uid=26 gid=26
```

man userdbpw

```
userdbpw  | userdb columbiangold/paul@columbiangold.ca set systempw
```
 

```
makeuserdb
```



Missed some file changes: So also run

```
chmod -R 0700 /usr/libexec/sm.bin/*
chown -R mailnull /usr/libexec/sm.bin/*
chown -R mailnull:mailnull /home/mail/*
```



At this point log out of the jail and double check your firewall for port 143 and 25 access if this is a VPS remote server and /etc/natd.conf always to redirect port 143 and 25. restart if necessary or just restart your jail. Also remove read/write permission that were changed in the file fstab.

Info  http://www.linuxscrew.com

Thanks for using the guide.


----------



## paulfrottawa (Oct 20, 2012)

When you test connect to the imap-server use no-encryption with this setup. 

https://www.cacert.org/ for a free certificate. 


If your not seeing your mail or not authenticating check /var/log/maillog on the server.

Please denote to the FreeBSD foundation i did.


----------

