域中有一个正常运行的 postfix/dovecot 服务器。客户决定改用 zoho,并将 MX 记录更改为 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,以便它们像普通电子邮件一样显示,带有附件等?
答案1
由于 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;
}
上述方法虽然有效,但还很粗糙,可能会触发反垃圾邮件措施,而且肯定可以在很多方面进行优化。