Can NethServer show emails that have been sent via an external device (Photocopier)?

Many softwares or devices allow you to send mails by relying on the company e-mail server.

The problem is that they don’t make a copy of the mails sent in “Sent Mail” of the account used if you use direct sending via SMTP.

Or you need to edit the sent email, in this case the email should go to “Drafts” of the account but not sent immediately, so you can allow the user to edit it and then send it independently.

In the case of the presence of mail client via Web like Webtop, the problem is definitely manifested because usually people try to avoid installing a mail client on their PCs.

It’s possible to configure Nethserver NG 7.x, and especially Postfix, to perform this operation automatically.

Postfix will listen on the non-standard ports 1587 or 1465 to which the sending agents must point.

In case the mails should end up in “Drafts” without being sent immediately, the agent must point to ports 2587 or2465.

By receiving mails on those ports, Postfix will also make a copy of those mails in the “Sent Items” of the corresponding accounts.

Edit the Postfix configuration file /etc/postfix/master.cf creating the template-custom

mkdir -p /etc/e-smith/templates-custom/etc/postfix/master.cf
cd /etc/e-smith/templates-custom/etc/postfix/master.cf

add the template-custom

vi 55submission

and insert in 55submission the lines

#
# 55submission

#
# Send mail and make a copy in Sent folder
# TCP ports 1587 (submission), 1465 (smtps) listeners
#

0.0.0.0:1587 inet n       -       n       -       -       smtpd
{
    $OUT = join("\n", map { "  -o " . $_ } @submission_smtpd_options);
}
  -o content_filter=sendandcopyinsent:

0.0.0.0:1465   inet	n	-	n	-	-	smtpd
  -o smtpd_tls_wrappermode=yes
{
    $OUT = join("\n", map { "  -o " . $_ } @submission_smtpd_options);
}
  -o content_filter=sendandcopyinsent:

sendandcopyinsent      unix    -       n       n       -       -       pipe
  flags=DRhu user=vmail:vmail argv=/var/lib/nethserver/filters/sendandcopyinsent -f $\{sender\} -- $\{recipient\}


#
# DO NOT Send mail and make a copy in Drafts folder
# TCP ports 2587 (submission), 2465 (smtps) listeners
#

0.0.0.0:2587 inet n       -       n       -       -       smtpd
{
    $OUT = join("\n", map { "  -o " . $_ } @submission_smtpd_options);
}
  -o content_filter=copyindrafts:

0.0.0.0:2465   inet	n	-	n	-	-	smtpd
  -o smtpd_tls_wrappermode=yes
{
    $OUT = join("\n", map { "  -o " . $_ } @submission_smtpd_options);
}
  -o content_filter=copyindrafts:

copyindrafts      unix    -       n       n       -       -       pipe
  flags=DRhu user=vmail:vmail argv=/var/lib/nethserver/filters/copyindrafts -f $\{sender\} -- $\{recipient\}

Expand and activate editing by typing

expand-template /etc/postfix/master.cf
postfix reload

Create the sendandcopyinsent filter that will handle the copy

mkdir -p /var/lib/nethserver/filters
cd /var/lib/nethserver/filters

vi sendandcopyinsent

and insert in sendandcopyinsent the lines

#!/bin/sh
 
# Simple shell-based filter. It is meant to be invoked as follows:
#       /path/to/script -f sender recipients...

# Localize these. The -G option does nothing before Postfix 2.3.
INSPECT_DIR=/var/spool/filter
SENDMAIL="/usr/sbin/sendmail -G -i" # NEVER NEVER NEVER use "-t" here.
 
# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
 
# Clean up when done or when aborting.
trap "rm -f in.$$" 0 1 2 3 15
 
# Start processing.
cd $INSPECT_DIR || {
    echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
 
cat >in.$$ || { 
    echo Cannot save mail to file; exit $EX_TEMPFAIL; }

# Specify your content filter here.
/usr/libexec/dovecot/dovecot-lda -f $2 -d $2 -m "Sent" <in.$$ || {
   echo Message content rejected; exit $EX_UNAVAILABLE; }

$SENDMAIL "$@" <in.$$

exit $?

Create the copyindrafts filter that will handle the copy

mkdir -p /var/lib/nethserver/filters
cd /var/lib/nethserver/filters

vi copyindrafts

and insert in copyindrafts the lines

#!/bin/sh
 
# Simple shell-based filter. It is meant to be invoked as follows:
#       /path/to/script -f sender recipients...

# Localize these. The -G option does nothing before Postfix 2.3.
INSPECT_DIR=/var/spool/filter
SENDMAIL="/usr/sbin/sendmail -G -i" # NEVER NEVER NEVER use "-t" here.
 
# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
 
# Clean up when done or when aborting.
trap "rm -f in.$$" 0 1 2 3 15
 
# Start processing.
cd $INSPECT_DIR || {
    echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
 
cat >in.$$ || { 
    echo Cannot save mail to file; exit $EX_TEMPFAIL; }

# Specify your content filter here.
/usr/libexec/dovecot/dovecot-lda -f $2 -d $2 -m "Drafts" <in.$$ || {
   echo Message content rejected; exit $EX_UNAVAILABLE; }

#$SENDMAIL "$@" <in.$$

exit $?

Set permissions to sendandcopyinsent and copyindrafts

cd /var/lib/nethserver/filters    
chmod 755 sendandcopyinsent copyindrafts
chown vmail:vmail sendandcopyinsent copyindrafts

Create the support directory /var/spool/filter

mkdir -p /var/spool/filter
chown vmail:vmail /var/spool/filter

Create a firewall rule to open ports 1587, 1465, 2587 and 2465 to trusted networks (green)

config set fw_sendandcopy service status enabled TCPPorts 1587,1465,2587,2465 access green
signal-event firewall-adjust
signal-event runlevel-adjust

If you want to open ports to untrusted networks as well (e.g. reds)

config set fw_sendandcopy service status enabled TCPPorts 1587,1465,2587,2465 access green,red
signal-event firewall-adjust
signal-event runlevel-adjust

Mail sending agents on programs, applications and devices will have to be configured to use non-custom ports so, if for example they used 465, they will have to be configured to use 1465 (if you want the email to be sent immediately and put a copy in “sent mail”) or 2465 (if you want the email to be put in “drafts” of the account so that it can be edited manually but not sent immediately), and they will follow the account authentication rules set on Nethserver as on normal ports.

Reference: http://www.postfix.org/FILTER_README.html

6 Likes