Chinaunix首页 | 论坛 | 博客
  • 博客访问: 579866
  • 博文数量: 142
  • 博客积分: 10016
  • 博客等级: 上将
  • 技术积分: 1835
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-10 14:30
个人简介

工作中~

文章分类

全部博文(142)

文章存档

2009年(25)

2008年(117)

我的朋友

分类:

2008-07-22 13:41:40

作者:lxq007


本文主要介绍了基于dovecot 的邮件自动回复 的配置过程。

我使用的系统及安装的软件包为Debian GNU/Linux 4.0、postfix 2.3.4-3 、squirrelmail   1.4.9a-1和 dovecot  1.0.13-2 。

dovecot 版本如果比较旧的话,配置自动回复时将不能给每个邮件用户设置文件。

-----------------------------------------------------------------------------------

配置时遇到的一些其他问题: "X-Spam-Flag"等在邮件信头不显示

 在重新配置邮件服务器时,安装完amavisd-new和squuirrelmail软件包后,并在devocot中进行配置。查看邮件日志:

 

 

nano /var/log/mail.log   

在日志中发现,amavisd生效,对邮件进行了打分,但在登录squirrelmail前台后,发现在邮件信头中不会显示"X-Spam-Flag"等信头信息,也就不会将垃圾邮件转移到indox.spam信箱中去。

经过寻找,终于发现问题原因,原来是由于域名不对,然后进行修改:

nano /etc/mailname

关于在debian上如何安装配置postfix+dovecot+squirremail+amavisd+spamassassion,请参考

Howto: ISP-style Email Server with Debian-Etch and Postfix 2.3

-----------------------------------------------------------------------------------

dovecot中的配置文件:dovecot.conf进行如下修改:

plugin {

sieve = /home/squirrelmail/data/%u/vacation.txt       //添加这行

#sieve = /home/squirrelmail/%d/%n/vacation.txt     //添加这行,用于测试

}

自动回复的脚步vacation.txt为:

require "vacation";
vacation
    :days 1
    :subject "test1"
"this is ts.";
redirect
t3@xxxxx.cn;
sieve = /home/vmail/yumail.cn/t7/sieve 这个为原来的脚步目录,sieve = /home/squirrelmail/data/%u/vacation.txt 为courier_vacation插件产生的脚本目录,courier_vacation源码进行了修改,这里的vacation.txt  包含了原来的vacation.txt\vacation_subject.txt\vacation_cc_addresses.txt,并且vacation.txt内写为了脚步形式,如上边的脚步)

其中%d 代表域名,%n代表用户文件t*/,%u代表了用户文件t*@xxxx.cn/ ,

这的vacation.txt文件为squirrelmail的插件courier_vacation产生的,由于执行这个脚步要生成一个vacation.txtc(注意此类脚步生成文件均为在本文件名后加"c"),所以在此要注意权限问题。可以:

chmod 777 /home/squirrelmail/data

--------------------------------------------------------------------------------

courier_vacation如何修改:使vacation.txt\vacation_subject.txt\vacation_cc_addresses.txt合而为一并输出为可执行的脚步?

  修改options.php文件:以下为修改部分的代码

function removeVacationFiles($homeDir)
{

   global $messageFileName, $subjectFileName, $ccAddressesFileName, $keepMessagesFileName;


   if (compatibility_check_sm_version(1, 3))
   {
      include_once (SM_PATH . 'plugins/courier_vacation/config.php');
   }
   else
   {
      include_once ('../plugins/courier_vacation/config.php');
   }


   // delete message text file
   //
   if (file_exists($homeDir . '/' . $messageFileName))
   {

      $FILE = @fopen($homeDir . '/' . $messageFileName, 'w');
  
   if (!$FILE)
   {
   showError('ERROR: Could not access vacation message');
   exit(1);
   }
   if (, " "))
   {
   fclose($FILE);
   showError('ERROR: Could not delete vacation message');
   exit(1);
   }
   fclose($FILE);

   } 

}

 

// creates (or overwrites) vacation files as needed
// removes files that should not be present (for example,
// if there was a subject file previously, but this
// time no subject is given, the subject file is removed)
//
function writeVacationFiles($homeDir, $messageText,
                            $messageSubject, $ccAddresses, $keepMessages)
{

   global $messageFileName, $subjectFileName,
          $ccAddressesFileName, $keepMessagesFileName;


   if (compatibility_check_sm_version(1, 3))
   {
      include_once (SM_PATH . 'plugins/courier_vacation/config.php');
   }
   else
   {
      include_once ('../plugins/courier_vacation/config.php');
   }


   // write message text
   //
   $msg = eregi_replace('', "\n", $messageText);
   $FILE = @fopen($homeDir . '/' . $messageFileName, 'w');
   exec("sudo chmod o+w ".$homeDir);
   if (!$FILE)
   {
      showError('ERROR: Could not access vacation message');
      exit(1);
   }
   $vacation_str = "require \"vacation\";\n";
   $vacation_str .= "vacation\n";
   $vacation_str .= "    :days 1\n";
   /*add subject*/
   if (!empty($messageSubject))
   {
      $vacation_str .= "    :subject \"".$messageSubject."\"\n";
   }  
  
   /*add mailbody*/
   if (empty($msg)) $msg = ' ';  // empty messages really screw things up
   $vacation_str .= "\"".$msg."\";\n";
  
   /*add redirect address*/
   if (!empty($ccAddresses))
   {
      // TODO: how can we make sure there are color: #ff0000;">  $vacation_str .="redirect \"".$ccAddr."\";\n";
  
       

      }
    
      // write flag file indicating to keep messages in this account (if needed)
      //
      if (!empty($keepMessages))
      {
        
         $vacation_str .="keep;\n";
      }
   }

  
   if (, $vacation_str))
   {
      fclose($FILE);
      showError('ERROR: Could not save vacation message');
      exit(1);
   }
   fclose($FILE);

 
}

 

// displays simple error output page
//
function showError($message)
{

   global $color;
   displayPageHeader($color, 'None');
   echo '

'
      . $message
      . '
';

}

 

// gets user's home directory location from backend
//
function getHomeDirectory($user)
{

   global $backend;


   // build correct function name
   //
   $backendFunction = $backend . '_get_home_directory';


   return $backendFunction($user);

}

 

// get user's home directory from a MySQL backend
//
function mysql_get_home_directory($user)
{

   global $mysql_server, $mysql_user, $mysql_pwd, $mysql_database,
          $mysql_home_field, $mysql_table, $mysql_userid_field;


   $ds = mysql_connect($mysql_server, $mysql_user, $mysql_pwd);
   if (!$ds)
   {
      showError('ERROR: Could not connect to database');
      exit(1);
   }

   if (!mysql_select_db($mysql_database, $ds))
   {
      showError('ERROR: Could not find database');
      exit(1);
   }

   $query_string = 'SELECT ' . $mysql_home_field
                 . ' FROM '  . $mysql_table
                 . ' WHERE ' . $mysql_userid_field . '="' . $user . '"';

   $select_result = mysql_query($query_string, $ds);
   
   if (!$select_result)
   {
      showError('ERROR: Database call failed');
      exit(1);
   }

   if (mysql_num_rows($select_result) != 1)
   {
      showError('ERROR: Could not fetch correct user info');
      exit(1);
   }

   // after all that...  get query results
   //
   $row = mysql_fetch_row($select_result);
   return $row[0];

}


function fixed_get_home_directory($user)
{
      global $fixed_directory;
     
      return sprintf($fixed_directory,$user);              
}

?>
修改config.php:

添加:   $backend = 'fixed';
   $fixed_directory = '/home/squirrelmail/data/%s';

 

修改完这些部分,自动回复便可实现啦。登录squirrelmail前台,在选项中点取"Vacation / Autoresponder ",进行自动回复设定,如下图:

不过由于本人系统为uft_8的,所以,配置完成后,自动回复只支持英文的,不支持中文。

                                                     

阅读(1991) | 评论(1) | 转发(0) |
0

上一篇:Maildrop(转)

下一篇:Dovecot Sieve plugin

给主人留下些什么吧!~~

chinaunix网友2008-09-11 10:11:10

感谢!对我很有帮助!但看起来比较难,我还没实现!