免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2545 | 回复: 1
打印 上一主题 下一主题

如何以非root用户执行sendmail发邮件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-12 14:53 |只看该作者 |倒序浏览
系统平台:AIX4.3.3,内置了sendmail8.9.3。
经过配置,root已可以使用sendmail命令发INTERNET邮件,但是切换到其它用户执行sendmail命令,一回车就结束了,没有任何提示,发不出邮件。经过查阅资料,知道sendmail一般情况下只能以root用户执行。请问可不可以让非root用户可以执行sendmail发邮件呢?如何设置?

论坛徽章:
0
2 [报告]
发表于 2010-05-13 17:37 |只看该作者
  1. 通过crontab 跑个程序通过以下的类来完成发邮件
  2. <?
  3. class smtp_mail
  4. {
  5.     var $host;
  6.     var $port;
  7.     var $user;
  8.     var $pass;
  9.     var $debug = false;
  10.     var $conn;
  11.     var $result_str;
  12.     var $in; //conmand send to smtp server
  13.     var $from;
  14.     var $to;
  15.     var $subject;
  16.     var $body;


  17.     function __destruct()
  18.     {

  19.     }
  20.     function __construct($host,$port,$user,$pass,$debug=false)
  21.     {
  22.         $this->host   = $host;
  23.         $this->port   = $port;
  24.         $this->user   = base64_encode($user);
  25.         $this->pass   = base64_encode($pass);
  26.         $this->debug  = $debug;
  27.         $this->socket = socket_create (AF_INET, SOCK_STREAM, 0);
  28.         if($this->socket)
  29.         {
  30.             $this->result_str  =  "create SOCKET:".socket_strerror(socket_last_error());
  31.             $this->debug_show($this->result_str);
  32.         }
  33.         else
  34.         {
  35.             die("init fail, check your parameter");
  36.         }
  37.         $this->conn = socket_connect($this->socket,$this->host,$this->port);
  38.         if($this->conn)
  39.         {
  40.             $this->result_str  =  "connect SOCKET:".socket_strerror(socket_last_error());
  41.             $this->debug_show($this->result_str);
  42.         }
  43.         else
  44.         {
  45.             exit("init fail, check your parameter");
  46.         }
  47.         $this->result_str = "server:".socket_read($this->socket, 1024);
  48.         $this->debug_show($this->result_str);
  49.     }
  50.     function debug_show($str)
  51.     {
  52.         if($this->debug)
  53.         {
  54.             echo $str."n";
  55.         }
  56.     }
  57.     function send($from,$to,$body)
  58.     {
  59.         if($from == "" || $to == "")
  60.         {
  61.             die("no from or to address");
  62.         }
  63.         $this->subject =  "mail user data".date('Y-m-d',time()-86400);
  64.         $this->body    =  $body;
  65.         $this->from     =  $from;
  66.         $this->to       =  $to;
  67.         $this->body     =  $body;

  68.         $All          = "From:<".$this->from.">\r\n";
  69.         $All          .= "To:<".$this->to.">\r\n";
  70.         $All          .= "Subject:".$this->subject."\r\n\r\n";
  71.         $All          .= $this->body;
  72.         //interactive with smtp server
  73.         $this->in       =  "EHLO HELO\r\n";
  74.         $this->docommand();

  75.         $this->in       =  "AUTH LOGIN\r\n";
  76.         $this->docommand();

  77.         $this->in       =  $this->user."\r\n";
  78.         $this->docommand();

  79.         $this->in       =  $this->pass."\r\n";
  80.         $this->docommand();

  81.         $this->in       =  "MAIL FROM:<".$this->from.">\r\n";
  82.         $this->docommand();

  83.         $this->in       =  "RCPT TO:<".$this->to.">\r\n";
  84.         $this->docommand();

  85.         $this->in       =  "DATA\r\n";
  86.         $this->docommand();

  87.         $this->in       =  $All."\r\n.\r\n";
  88.         $this->docommand();

  89.         $this->in       =  "QUIT\r\n";
  90.         $this->docommand();

  91.         //interactive end
  92.     }
  93.     function docommand()
  94.     {
  95.         socket_write($this->socket, $this->in, strlen($this->in));
  96.         $this->debug_show("client:".$this->in);
  97.         $this->result_str = "server:".socket_read($this->socket, 1024);
  98.         $this->debug_show($this->result_str);
  99.     }
  100. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP