There was a working postfix/dovecot server running on a domain. The client decided to use zoho instead, and changed the MX records to zoho. Before DNS propagated, a hundred or so emails made it through to the original server.

So inside /var/mail/vhosts/ravingo.in/rk/new, for example ...

-rw------- 3 vmail vmail 24128 Sep 12 09:29 1473672547.M984731P30716.ravingo.ravingo.id,S=24128,W=24567 -rw------- 1 vmail vmail 52287 Sep 12 10:48 1473677302.M251841P31240.ravingo.ravingo.id,S=52287,W=53023 -rw------- 2 vmail vmail 165851 Sep 12 14:08 1473689331.M885291P32352.ravingo.ravingo.id,S=165851,W=168081

Is there a way to pipe these messages to Zoho, so they show up like regular emails, with attachments, etc.?

1 Answer 1


Since each file in a Maildir is already a complete e-mail message it is simple matter of setting up an SMTP session to Zoho's mailserver and then deliver those messages again.

A trivial bit of perl:

#!/usr/bin/perl -w
## purpose: send the contents of a Maildir over SMTP
## usage:   perl this_program
my $MAILDIR = '/home/hbruijn/Maildir/cur/' ;

# The mailserver to deliver the messages to:
my $MAILHOST = 'smtp.example.com' ;

# The email address of the recipient on $MAILHOST:
my $RECIPIENT = '[email protected]' ;

# The email address of the sender in the SMTP envelope and the one to receive errors and bounces:
my $SENDER = '[email protected]' ;

use Net::SMTP;

foreach my $MESSAGE (glob("$MAILDIR/*")) {
        printf "%s\n", $MESSAGE;
        my $smtp = Net::SMTP->new($MAILHOST);
        if ($smtp->to($RECIPIENT)) {
                open my $fh, "<", $MESSAGE or die "can't read open '$MESSAGE': $OS_ERROR";
                while (<$fh>) {
                close $fh or die "can't read close '$MESSAGE': $OS_ERROR";
        } else {
                print "Error: ", $smtp->message();

The above works, but is quite crude, may trigger anti-spam measures and can definitely be optimised in many ways.

  • I searched for PHP variants, but they all require splitting the message into header/body. I'll give Perl a whirl, thanks :)
    – neokio
    Sep 22, 2016 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .