用WinSocket发送邮件(150分)

  • 主题发起人 主题发起人 praisesoft
  • 开始时间 开始时间
P

praisesoft

Unregistered / Unconfirmed
GUEST, unregistred user!
用WinSock API &nbsp;模式:TCP<br>1.用WinSocket发送邮件,帮看看是那里出错了,认证不成功。<br>2.祝大家新年快乐,万事如意!
 
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> &nbsp;const atLogin: BOOL = False): TSocket;<br>var<br> &nbsp;CmdRet: TCmdRet;<br>begin<br> &nbsp;Result := DoConnect(Server, nil, Port);<br> &nbsp;if ValidSocket(Result) and MailResponse(MailReadLine(Result), 220) then<br> &nbsp;begin<br> &nbsp; &nbsp;//atLogin 要认证<br> &nbsp; &nbsp;if atLogin then begin<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, 'EHLO ', 'www.000.com', 250);<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, 'AUTH LOGIN ', nil, 250);<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, 'PIPELINING ', nil, 250);<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, 'SIZE ', nil, 250);<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, 'ETRN ', nil, 250);<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, '8BITMIME ', nil, 250);<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, 'USER ', PChar(Base64Encode(UserName)), 334);<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, 'PASS ', PChar(Base64Encode(PassWord)), 235);<br> &nbsp; &nbsp; &nbsp;if not CmdRet.Result then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;StopSocket(Result);<br> &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage('authentication failed.');<br> &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else begin<br> &nbsp; &nbsp; &nbsp;CmdRet:= MailCommand(Result, 'HELO ', '163.test.com', 250);<br> &nbsp; &nbsp; &nbsp;if not CmdRet.Result then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage('Cmd HELO failed');<br> &nbsp; &nbsp; &nbsp; &nbsp;StopSocket(Result);<br> &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;end else //if ValidSocket(Result) and Pop3Response(Result) then<br> &nbsp;begin<br> &nbsp; &nbsp;StopSocket(Result);<br> &nbsp;end;<br>end;<br><br>function SendMail(const S: TSocket; Body, Subject, Addres, From: PChar;<br> const Attachment: PChar = nil): BOOL;<br>var<br> &nbsp;CmdRet: TCmdRet;<br>begin &nbsp; &nbsp; &nbsp; &nbsp; //'MAIL FROM: &lt;getoicq@21cn.com&gt;'+CRLF;<br> &nbsp;Result := False;<br> &nbsp;CmdRet := MailCommand(S, 'MAIL FROM: ', From, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;CmdRet := MailCommand(S, 'RCPT TO: ', From, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;CmdRet := MailCommand(S, 'DATA', nil, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;CmdRet := MailCommand(S, 'From:', From, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;CmdRet := MailCommand(S, 'To:', Addres, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;CmdRet := MailCommand(S, 'Subject:', Subject, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;CmdRet := MailCommand(S, nil, Body, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;CmdRet := MailCommand(S, '.', nil, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;CmdRet := MailCommand(S, 'QUIT', nil, 250);<br> &nbsp;if not CmdRet.Result then<br> &nbsp;begin<br> &nbsp;end;<br> &nbsp;Result := True;<br>end;
 
认证要Base64编码
 
网址大全:&lt;a href=&quot;http://3711.855.com&quot;&gt;http://3711.855.com&lt;/a&gt; 在这里你可以找你想要的网站!
 
新年快乐,万事如意!
 
新年快乐,万事如意!
 
后退
顶部