最近研究的一个socket发email的程序
最近研究的一个socket发email的程序
1 use Socket;
use MIME::Base64;
socket(SOCK,AF_INET,SOCK_STREAM,getprotobyname('tcp'));
$sin=sockaddr_in(25,inet_aton("smtp.163.com"));
connect(SOCK,$sin);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$sd="EHLO username\@163.com\r\n"; #username@163.com 替换成email
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$sd="auth login\r\n";
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$user="username"; #替换成用户名
$pw="password"; #替换成口令
$sendto="<username\@163.com>\r\n"; #username@163.com 替换成email
$sub="主题";
$body="你好,这里是从perl发出的信件";
$sd=encode_base64($user);
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$sd=encode_base64($pw);
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$sd="mail from:<username\@163.com>\r\n"; #username@163.com 替换成自己的email
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$sd="RCPT TO:".$sendto."\r\n";
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$sd="DATA\r\n";
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$sd="subject:".$sub."\r\n";
print "SEND: ".$sd;
send(SOCK,$sd,undef);
$sd="\r\n";
print "SEND: ".$sd;
send(SOCK,$sd,undef);
$sd=$body;
print "SEND: ".$sd;
send(SOCK,$sd,undef);
$sd="\r\n.\r\n";
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
$sd="QUIT";
print "SEND: ".$sd;
send(SOCK,$sd,undef);
recv(SOCK,$rv,1024,undef);
print "RECV: $rv";
shutdown(SOCK,2);