如题,另外,能不能附原码?

解决方案 »

  1.   

    想做一个类似FoxMail的东西,不过在发附件时卡住了,所以想向大家请教一下怎么发附件.呵呵
      

  2.   

    用什么效率高我不知道用indySMTP我实现过发邮件,带附件也可以参考fastreport的发送邮件,代码很详细
      

  3.   

    function TFrmSendEmail.SendEmail(EmailHost:String;MailTitle:String;MailUsername,MailPassword:String;
                       EmailServerPort,EmailAuthType:Integer;EmailUserEmail:String): boolean;
    var
     i,j,k,fgfIndex:Integer;
     AttachmentFileName:String;
     S:AnsiString;
     tmpEMailItem,tmpCCEMailItem : TIdEMailAddressItem;
     AttachmentFileSize:Integer;
    begin
      With IdMessage1 Do
      begin
         Body.Clear;
         Body.Assign(MailBody.Lines);
         {CharSet:='utf-8';//gb2312';
         ContentType := CharSet;
         ContentTransferEncoding := ContentType;}//影响正文     From.Address:=MailUsername; //你要发送邮件的完整地址'
         From.Name   :=MailUsername;//'发件人';
         From.Text:=EmailUserEmail;
         //Recipients.Add.Address:=Trim(RecvieMemo.Lines.Text);
         Recipients.EMailAddresses:=Trim(RecvieMemo.Lines.Text);//'发送者地址';   
         for I := 0 to RecvieMemo.Lines.Count - 1 do    //收件人实现群发
         begin
            S:=S+RecvieMemo.Lines.Strings[i];
         end;
         k:=0;
         j:=Pos(';',S);
         if j>0 then
             tmpEMailItem := IdMessage1.BccList.Add;  //添加一个地址列表
         while j>0 do
         begin
            tmpEMailItem.Address:=Copy(S,0,j-1);
            S:=Copy(S,j+1,MaxInt);
            j:=Pos(';',S);
            Inc(k);
         end;
         if k>0 then
            tmpEMailItem.Address:=S; //最后一个     S:='';
         for I := 0 to ReciveSecMemo.Lines.Count - 1 do    //抄写人实现群发
         begin
            S:=S+ReciveSecMemo.Lines.Strings[i];
         end;
         k:=0;
         j:=Pos(';',S);
         if j>0 then
             tmpCCEMailItem := IdMessage1.CCList.Add;  //添加一个地址列表
         while j>0 do
         begin
            tmpCCEMailItem.Address :=Copy(S,0,j-1);
            S:=Copy(S,j+1,MaxInt);
            j:=Pos(';',S);
            Inc(k);
         end;
         if k>0 then
            tmpCCEMailItem.Address:=S; //最后一个     Subject:=MailTitle;//主题
         with TIdText.Create(IdMessage1.MessageParts, MailBody.Lines) do
         begin
              ContentType := 'text/plain';
         end;
         IdMessage1.MessageParts.Clear;
         for I := 0 to MailAppen.Items.Count - 1 do
         begin
             AttachmentFileName := MailAppen.Items.Strings[i];
             if fileExists(AttachmentFileName) then
             begin
                  AttachmentFileSize:=AttachmentFileSize+GetSendAttchmentFileSizeof(AttachmentFileName);
                  if i > 0 then MessageParts.Add;
                  if FileExists(AttachmentFileName) then
                     TIdAttachmentFile.Create(IdMessage1.MessageParts, AttachmentFileName);
             end;
         end;
      end;
      ProgressBar1.Max:=AttachmentFileSize;
      With IdSMTP1 Do
      begin
         try
             Disconnect;
             {authentication settings}
             case SmtpAuthType of
               0: AuthType := atNone;
               1: AuthType := atDefault; {Simple Login}
             end;
             Username := MailUsername;
             Password := MailPassword;
             IdSMTP1.PipeLine:=False;//可以避开瑞星的监控
             {General setup}
             Host := EmailHost;
             Port := SmtpServerPort;
             ConnectTimeout:=300000;
             Application.ProcessMessages;
             Connect();  //连接SMTP服务器
             Application.ProcessMessages;
             Authenticate;
             try
             Application.ProcessMessages;
             Send(IdMessage1);  //向服务器发送邮箱
             Except
             end;
         Finally
             Disconnect;
         end;
      end;end;