HOWTO read a local mailbox using SSH on LINUX

From NHI1
Jump to: navigation, search

The problem sounds easy and it is, in fact, easy

  • The goal is to transfer the emails from the local mailbox of source_host to the target_host.
  • Deliver the emails to the user on target_host

With this easy setup the emails are delivered in raw format.

create a script on source_host of email

example: $HOME/bin/forward_email_from_remote.bash

 #!/bin/bash
 
 if [[ ! -z "$MAIL" ]] ; then
    /usr/bin/cat $MAIL
    /usr/bin/truncate --size 0 $MAIL
 fi
 

create a crontab entry on target_host of the email

  1. man 5 crontab
  2. crontab -e
  3. minutes_to_set * * * * ssh user@source_host bin/forward_email_from_remote.bash