Sending mails from a jail through the host

Hi.

I have to isolate an old PHP application inside a FreeBSD jail. However, would it be possible to send mails, from this jail, via the SMTP server of the host ?
I have an OpenSMTPd on the host, configured using relays, on port 25, and I don't want to configure another OpenSMTPd on the jail, it would be redondant, just for an old web app.

The /etc/jail.conf (host):
Code:
myjail {
  # STARTUP/LOGGING
  exec.start = "/bin/sh /etc/rc";
  exec.stop = "/bin/sh /etc/rc.shutdown";
  exec.consolelog = "/var/log/jail_console_${name}.log";

  # PERMISSIONS
  allow.raw_sockets;
  exec.clean;
  mount.devfs;

  # HOSTNAME/PATH
  host.hostname = "${name}";
  path = "/jails/containers/${name}";

  # NETWORK
  ip4.addr = "192.168.1.201";
  interface = em0;

  # MISC
  jid = 1;
  persist;
}

Here's the /usr/local/etc/mail/smtpd.conf (host):
Code:
table aliases file:/etc/mail/aliases
table secrets file:/usr/local/etc/mail/secrets

listen on em0
action "local" maildir alias <aliases>
action "relay" relay host smtps://user@provider.tld auth <secrets>

match for local action "local"
match from local for any action "relay"
match from src "192.168.1.201" for any action "relay"

Here's the /usr/local/etc/mail/smtpd.conf (jail):
Code:
listen on localhost
action "local" maildir
action "relay" relay host smtps://192.168.1.10

match for local action "local"
match from local for any action "relay"

On the jail, when I'm trying to send an email with echo "test" | mail myuser@whateverdomain.tld, I got this in /var/log/maillog :
Code:
smtp connected address=local host=hostname.domain.tld
smtp message msgid=a06cf5db size=345 nrcpt=1 proto=ESMTP
smtp envelope evpid=a06cf5dbfbf2f1c1 from=<root@hostname.domain.tld> to=<user@domain.tld>
smtp disconnected reason=quit
mta connecting address=smtps://192.168.1.10:465 host=192.168.1.10
mta error reason=IO Error: Connection refused
smtp-out: Disabling route [] <-> 192.168.1.10 (192.168.1.10) for 15s

However I have nothing on the host's /var/log/mailog. But a telnet 192.168.1.10 25 seems to be good:
Code:
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.

On the host, a sockstat -l|grep 25 returns this:
Code:
_smtpd   smtpd      19082 11  tcp4   192.168.1.10:25       *:*
_smtpd   smtpd      19082 12  tcp4   192.168.1.201:25      *:*

On the jail:
Code:
_smtpd   smtpd      19179 9   tcp4   192.168.1.201:25      *:*

Any ideas? I'd like to send emails from the jail, through the OpenSMTPd installed on the host. What did I mess? Maybe a better solution? I'm open.

Thanks a lot in advance.

Regards,
 
Haha, ok found writing the post ?

In the /usr/local/etc/mail/smtpd.conf (jail), replace:
Code:
action "relay" relay host smtps://192.168.1.10
By :
Code:
action "relay" relay host smtp://192.168.1.10
The smtp host server does not listen on smtps...


More, in
/usr/local/etc/mail/smtpd.conf (host), I can remove the line match from src "192.168.1.201" for any action "relay". Does it because it considers host and jail have the "same" real IP?

However, if you have suggestions, or better ideas, I'll take a look. I'm really new to jail concept.

Regards,
 
I use sendmail inside a jail to send mail to the relay on the host.
Sendmail configuration process is not very clear for me, but sendmail is already installed and it works for me for a long time.

Setup proper hostname for jail
cd /etc/mail
make
edit <hostname>.submit.mc
Add: FEATURE(`msp', `[relay_IP]')dnl
make
make install
make restart

or something similar.

p.s.
for FreeBSD 14 sendmail is not a default mail transport agent.

p.p.s
For more difficult cases I prefer to use postfix (at host and inside a jails).
 
Back
Top