来宾发言:我想用IDSMTP组件发送邮件,其中的SMTP服务器名(比如用yahoo.com.cn发送邮件)怎么填啊?还有怎么添加附件啊? 

解决方案 »

  1.   

    yahoo 的免费用户是不支持SMTP,一般支持的会在页面上写出smtp的地址
      

  2.   

    var
      IdMessage1: TIdMessage;
      IdSASLLogin1: TIdSASLLogin;
      IdSMTP1: TIdSMTP;
      LHlogin: TIdUserPassProvider;
    begin
      result:=0;
      idMessage1:=TIdMessage.Create();
      IdSASLLogin1:=TIdSASLLogin.Create();
      IdSMTP1:=TIdSMTP.Create();
      LHlogin:=TIdUserPassProvider.Create();
      with idMessage1 do
      begin
        ContentType:='text/html';
        Body.LoadFromFile(STRfname);
        From.Address:=STRfromEMail;
        Recipients.EMailAddresses:=STRReEmail;
        IDMessage1.Subject:=STRsubject;
      end;
      with IDSMTP1 do
      begin
        Host:=STRHost;
        port:=INTport;
        username:=STRusername;
        password:=STRpassword;
        LHlogin.Username:=STRuserName;
        LHlogin.Password:=STRpassWord;
        IDSMTP1.AuthType:=atSASL;
        IDSMTP1.SASLMechanisms.Add.SASL:=IdSASLLogin1;
        IdSASLLogin1.UserPassProvider:=LHlogin;
        try
          idsmtp1.Connect;
          idsmtp1.Authenticate;
          idsmtp1.Send(idMessage1);
          idsmtp1.Disconnect;
          result:=1;
        finally
        end;
      end;
      idMessage1.Free;
      IdSASLLogin1.Free;
      IdSMTP1.Free;
      LHlogin.Free;
    end;