1.用WinSocket发送邮件,帮看看是那里出错了,认证不成功。<br>{<br>220 163.com Coremail SMTP(Anti Spam) System<br>250-mail<br>250-PIPELINING<br>250-AUTH LOGIN PLAIN NTLM<br>250-AUTH=LOGIN PLAIN NTLM<br>250 8BITMIME<br>334 dXNlcm5hbWU6<br>334 UGFzc3dvcmQ6<br>535 Error: authentication failed<br>}<br>//Loging Smtp server<br>function SmtpLogin(Server: PChar; Port: Word; UserName, PassWord: PChar;<br> const atLogin: BOOL = False): TSocket;<br>var<br> CmdRet: TCmdRet;<br>begin<br> Result := DoConnect(Server, nil, Port);<br> if ValidSocket(Result) and MailResponse(MailReadLine(Result), 220) then<br> begin<br> //atLogin 要认证<br> if atLogin then begin<br> CmdRet:= MailCommand(Result, 'EHLO ', 'www.000.com', 250);<br> CmdRet:= MailCommand(Result, 'AUTH LOGIN ', nil, 250);<br> CmdRet:= MailCommand(Result, 'PIPELINING ', nil, 250);<br> CmdRet:= MailCommand(Result, 'SIZE ', nil, 250);<br> CmdRet:= MailCommand(Result, 'ETRN ', nil, 250);<br> CmdRet:= MailCommand(Result, '8BITMIME ', nil, 250);<br> CmdRet:= MailCommand(Result, 'USER ', PChar(Base64Encode(UserName)), 334);<br> CmdRet:= MailCommand(Result, 'PASS ', PChar(Base64Encode(PassWord)), 235);<br> if not CmdRet.Result then begin<br> StopSocket(Result);<br> ShowMessage('authentication failed.');<br> Exit;<br> end;<br> end<br> else begin<br> CmdRet:= MailCommand(Result, 'HELO ', '163.test.com', 250);<br> if not CmdRet.Result then<br> begin<br> ShowMessage('Cmd HELO failed');<br> StopSocket(Result);<br> Exit;<br> end;<br> end;<br> end else //if ValidSocket(Result) and Pop3Response(Result) then<br> begin<br> StopSocket(Result);<br> end;<br>end;<br><br>function SendMail(const S: TSocket; Body, Subject, Addres, From: PChar;<br> const Attachment: PChar = nil): BOOL;<br>var<br> CmdRet: TCmdRet;<br>begin //'MAIL FROM: <getoicq@21cn.com>'+CRLF;<br> Result := False;<br> CmdRet := MailCommand(S, 'MAIL FROM: ', From, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> CmdRet := MailCommand(S, 'RCPT TO: ', From, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> CmdRet := MailCommand(S, 'DATA', nil, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> CmdRet := MailCommand(S, 'From:', From, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> CmdRet := MailCommand(S, 'To:', Addres, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> CmdRet := MailCommand(S, 'Subject:', Subject, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> CmdRet := MailCommand(S, nil, Body, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> CmdRet := MailCommand(S, '.', nil, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> CmdRet := MailCommand(S, 'QUIT', nil, 250);<br> if not CmdRet.Result then<br> begin<br> end;<br> Result := True;<br>end;