急切盼望各位高手解答。

解决方案 »

  1.   

    用Delphi7中的IDSmtp控件和IdMessage控件。下面是源代码:
      IdSmtp1.AuthenticationType:=atLogin; //SMTP验证采用登录方式
      IdSmtp1.Username := '[email protected]';//发送人Email
      IdSmtp1.Password := 'yourpasswd';//发送人Email的密码
      IdSmtp1.Host := 'smtp.163.com';//smtp服务器  with IdMessage1 do
      begin
        body.Clear;
        Body.Add(' 这是正文!');
        Body.Add(' 正文第二行');
        Recipients.EMailAddresses := '[email protected]';//收件人EMail
        from.Address := IdSmtp1.Username;//发送人
        //Organization := 'mysoft' ;
        Subject := '你好!Email标题';
        //date := now(); //发送时间
      end;
      IdMessage1.MessageParts.Clear;
      TIdAttachment.Create(IdMessage1.MessageParts, 'C:\附件.zip');
      try
        IdSmtp1.Connect;
        IdSmtp1.Send(IdMessage1);
      finally
        IdSmtp1.Disconnect;
      end;
      

  2.   

    代码如下:
    const
      BaseTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';function EncodeBase64(Source: string): string;
    var
      Times, LenSrc, i: Integer;
      x1, x2, x3, x4: Char;
      xt: Byte;
    begin
      Result := '';
      LenSrc := Length(Source);
      if LenSrc mod 3 = 0 then
        Times := LenSrc div 3
      else
        Times := LenSrc div 3 + 1;
      for i := 0 to Times - 1 do
      begin
        if LenSrc >= (3 + i * 3) then
        begin
          x1 := BaseTable[(ord(Source[1 + i * 3]) shr 2)+1];
          xt := (ord(Source[1 + i * 3]) shl 4) and 48;
          xt := xt or (ord(Source[2 + i * 3]) shr 4);
          x2 := BaseTable[xt + 1];
          xt := (Ord(Source[2 + i * 3]) shl 2) and 60;
          xt := xt or (Ord(Source[3 + i * 3]) shr 6);
          x3 := BaseTable[xt + 1];
          xt := (ord(Source[3 + i * 3]) and 63);
          x4 := BaseTable[xt + 1];
        end
        else if LenSrc >= (2 + i * 3) then
        begin
          x1 := BaseTable[(Ord(Source[1 + i * 3]) shr 2) + 1];
          xt := (Ord(Source[1 + i * 3]) shl 4) and 48;
          xt := xt or (Ord(Source[2 + i * 3]) shr 4);
          x2 := BaseTable[xt + 1];
          xt := (Ord(Source[2 + i * 3]) shl 2) and 60;
          x3 := BaseTable[xt + 1];
          x4 := '=';
        end else
        begin
          x1 := BaseTable[(Ord(Source[1 + i * 3]) shr 2)+1];
          xt := (Ord(Source[1 + i * 3]) shl 4) and 48;
          x2 := BaseTable[xt + 1];
          x3 := '=';
          x4 := '=';
        end;
        Result := Result + x1 + x2 + x3 + x4;
      end;
    end;procedure NMSMTPConnect(Sender: TObject);
    var
      AuthOK: Boolean;
    begin
      AuthOK := False;
      NMSMTP.Transaction('auth login');
      if NMSMTP.ReplyNumber <> 500 then
      begin
        if NMSMTP.ReplyNumber = 334 then
        begin
          NMSMTP.Transaction(EncodeBase64(EditUserName.Text));  // UserName
          NMSMTP.Transaction(EncodeBase64(EditPassword.Text));  // Password
        end;
        if NMSMTP.ReplyNumber = 235 then
           ShowMessage('验证成功!')
        else
           ShowMessage('验证失败!');
      end
      else
        ShowMessage('该SMTP服务器无需用户验证。');
    end;----------------------------------------------
    这是D7的,和D6应该差不多吧.看看对你有没有帮助
    procedure Tfmail.BitBtn1Click(Sender: TObject);
    begin
      fm2.Lines.Add('正在连接服务器请等待...');
      with IdSMTP1 do
      begin
        Host :=trim(FEd_fwq.Text);
        Port:=25;
        Username:=trim(FEd_name.text);
        Password:=trim(FEd_pw.text);
        try
          Connect();
          except
            begin
            FM2.Lines.Add('无法连接到服务器!'+FEd_fwq.text);
            exit;
            end;
           fm2.Lines.Add('连接服务器成功!');
        end;
      end;
      if(IdSMTP1.AuthSchemesSupported.IndexOf('LOGIN'))<>-1 then
      begin
        fm2.Lines.Add('服务器要求验证');
        IdSMTP1.AuthenticationType:=atlogin;
        fm2.Lines.Add('开始验证...');
        try
          if IdSMTP1.Authenticate then
          fm2.Lines.Add('验证成功')
          else fm2.Lines.Add('验证失败');
          except
          begin
            fm2.Lines.Add('验证失败');
            IdSMTP1.Disconnect;
            exit;
          end;
         end;
       end else fm2.Lines.Add('服务器不要求验证');
       IdMessage1.MessageParts.Clear;
      with IdMessage1 do
      begin
        From.Address:=FEd_fxr.text;
        Recipients.EMailAddresses:=FEd_sxr.text;
        Body.Add(fm1.Text);
        Subject:=fed_zt.text;
        //AttachmentEncoding:=;
        if trim(FEd_fj1.Text)<>'' then TIdAttachment.Create(IdMessage1.MessageParts,FEd_fj1.Text);
        if trim(fed_fj2.text)<>'' then tidattachment.Create(IdMessage1.MessageParts,fed_fj2.text); 
      end;  try
        IdSMTP1.Send(IdMessage1);
        except
        begin
          fm2.Lines.Add('发送失败');
          IdSMTP1.Disconnect; //断开服务器连接
          exit;
        end;
       end;
      fm2.Lines.Add('发送成功');
      IdSMTP1.Disconnect;
    end;
      

  3.   

    小弟用纯winsock编写一个可以认证的发信软件,需要的话可以发信到[email protected]