有一个运行在域上的postfix / dovecot服务器。 客户决定使用zoho,并将MXlogging更改为zoho。 在DNS传播之前,有一百封左右的电子邮件通过了原始的服务器。
所以在/var/mail/vhosts/ravingo.in/rk/new ,例如…
-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
有没有办法将这些消息传递给Zoho,所以他们像普通的电子邮件,附件等显示?
由于Maildir中的每个文件都是一个完整的电子邮件,所以设置一个到Zoho的邮件服务器的SMTP会话,然后再传递这些消息是很简单的。
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); $smtp->mail($SENDER); if ($smtp->to($RECIPIENT)) { $smtp->data(); open my $fh, "<", $MESSAGE or die "can't read open '$MESSAGE': $OS_ERROR"; while (<$fh>) { $smtp->datasend($_); } $smtp->dataend(); close $fh or die "can't read close '$MESSAGE': $OS_ERROR"; } else { print "Error: ", $smtp->message(); }; $smtp->quit; }
以上的工作,但相当粗糙,可能会触发反垃圾邮件的措施,绝对可以在很多方面进行优化。