情况是这样的:我用TIdSMTP.send(TIdMessage)发送的邮件不能显示空格啊,原来我们公司的邮件系统用IE浏览,就把邮件中的空格过滤了。现在我想发送网页邮件应该就可以了。但是不知道怎么设置?请帮帮我。很急,在线等待。

解决方案 »

  1.   

    I use idSMTP component and idMessage. Here is one old example I found, but you have to add your HTMLs to TidMessage component.uses idMessage;function TfrmMain.SendMail(FileToSend: String): String;
    var
      MailMsg        : TidMessage;
      MailFile       : TidAttachment;
    begin
      // send the mail with the attachment
      MailMsg := TidMessage.Create(idSMTP);
      // from
      MailMsg.From.Address := '[email protected]';
      MailMsg.From.Name    := '[email protected]';
      MailMsg.Recipients.Add;
      MailMsg.Recipients.Items[0].Address := '[email protected]';
      //
    //  MailMsg.ReplyTo.      := GetOption('FromAddress');
      MailMsg.Subject      := 'Screenshot created on ' +
                              FormatDateTime('dd.mm.yyyy hh:nn:ss', Now);
      // the attachment
      MailFile             := TidAttachment.Create(MailMsg.MessageParts, FileToSend);
      MailFile.DisplayName := MailMsg.Subject;  // connect to server
      try
        idSMTP.Connect();
      except
        on E : Exception do
           Exit;
      end;  // send
      try
        idSMTP.Send(MailMsg);
      except
        on E: Exception do
            Exit;
      end;
      AddToLog('Message sent.', clGreen);  // close connection and free memory
      idSMTP.Disconnect;
      MailFile.Free;
      MailMsg.Free;
    end;
      

  2.   

    procedure TFormMain.SendMail(Recipient, Address: string);
    const
      sStars = 'BackgroundStars.jpg';
    var
      AdressItem: TIdEMailAddressItem;
      AFile: string;
      AMessage: TIdMessage;
      ASMTP: TIdSMTP;
      AStream: TMemoryStream;
      Attachment: TIdAttachment;
      IdBody: TIdText;
      IdHTML: TIdText;
      idStars: TIdAttachment;
      resStars: TStream;
      TempFile: TStream;
    begin
      Screen.Cursor := crHourGlass;
      AFile := FileListBox.FileName;
      if FileExists(AFile) then begin
        AMessage := TIdMessage.Create(nil);
        AMessage.NoDecode := False;
        AMessage.NoEncode := False;
        AMessage.ContentType := 'multipart/mixed';
        AMessage.Encoding := meMIME;
        AMessage.MsgId := 'PrettyPic';
        AMessage.References := ChangeFileExt(ExtractFileName(AFile), '');
        // Set recipients.
        AdressItem := AMessage.Recipients.Add;
        AdressItem.Name := Recipient;
        AdressItem.Address := Address;
        // Set subject.
        AMessage.Subject := 'Hello.';
        // Set sender.
        AMessage.Sender.Name := 'Workshop Alex';
        AMessage.Sender.Address := '[email protected]';
        // Set from.
        AMessage.From.Name := AMessage.Sender.Name;
        AMessage.From.Address := AMessage.Sender.Address;
        // Create plain body.
        IdBody := TIdText.Create(AMessage.MessageParts);
        IdBody.ContentType := 'text/plain';
        IdBody.Body.Add('Hello, friends.');
        IdBody.Body.Add('');
        // Add more to the plain-text bodypart.
        // Create HTML body.
        IdHTML := TIdText.Create(AMessage.MessageParts);
        IdHTML.ContentType := 'text/html; charset=US-ASCII';
        IdHTML.ContentTransfer := '7bit';
        IdHTML.Body.Add('<html>');
        IdHTML.Body.Add('  <head>');
        IdHTML.Body.Add('    <title>Hello</title>');
        IdHTML.Body.Add('  </head>');
        IdHTML.Body.Add('  <body title="' + AMessage.References + '" background="cid:BackgroundStars">');
        IdHTML.Body.Add('    Hello, friends.<br>');
        IdHTML.Body.Add('    <br>');
        IdHTML.Body.Add('    <img src="cid:PrettyPic" alt="' + ExtractFileName(AFile) + '" name="' + ExtractFileName(AFile) + '" title="Just an image included.">');
        IdHTML.Body.Add('  </body>');
        IdHTML.Body.Add('</html>');
        // Add the attachment. Don't forget the extra headers!
        Attachment := TIdAttachment.Create(AMessage.MessageParts, AFile);
        Attachment.ExtraHeaders.Values['Content-ID'] := '<PrettyPic>';
        Attachment.ContentType := 'image/jpeg';
        idStars := TIdAttachment.Create(AMessage.MessageParts, ExtractFilePath(ParamStr(0)) + sStars);
        idStars.ExtraHeaders.Values['Content-ID'] := '<BackgroundStars>';
        idStars.ContentType := 'image/jpeg';
        // Now send the thing...
        ASMTP := TIdSMTP.Create(nil);
        ASMTP.Host := 'mail.whatever.org';
        ASMTP.Port := 25;
        ASMTP.AuthenticationType := atNone;
        ASMTP.Connect;
        try
          ASMTP.Send(AMessage);
        except
          on E: Exception do ShowMessageFmt('Error: %s', [E.Message]);
        end;
        ASMTP.Disconnect;
        AMessage.Free;
        ASMTP.Free;
      end;
      Screen.Cursor := crDefault;
    end;
      

  3.   

    不行啊。好像是要设置idmessage.contenttype吧?
      

  4.   

    用outlook做一个网页邮件,保存成eml
    用记事本打开,自己分析一下格式,然后再写代码。