Genauso bin ich bei meinem erwähnten "Versuchs-Projekt" vorgegangen. Daher funktioniert mein Programm mit unformatiertem Text einwandfrei.
Versucht habe ich mich zunächst mit Formatierungen im RichEdit-Feld mit folgendem Code:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
| var b: TIdMessageBuilderRtf; s: TStringStream; begin s := TSTringStream.Create; try
RE1.Lines.SaveToStream(s); b := TIdMessageBuilderRtf.Create; try s.Position := 0; b.Rtf.LoadFromStream(s); b.FillMessage(IdMessage1); finally b.Free; end;
finally s.Free; end;
try IdMessage1.From.Address := edFrom.Text; IdMessage1.Subject := eBetreff.Text; IdMessage1.ContentType:='application/rtf';
IdSMTP1.Connect; IdMessage1.Recipients.EMailAddresses := edTo.Text; IdSMTP1.Send(IdMessage1); finally IdSMTP1.Disconnect; end; |
Schaue ich mir die ankommende E-Mail in meinem Web-Client an, sehe ich ein leeres Textfeld und einen mit „Teilstück 1“ bezeichneten Anhang ohne Dateierweiterung. Öffne ich diesen Anhang mit Wordpad, sehe ich meinen formatierten Text.
In Outlook empfange ich eine E-Mail ohne Text mit zwei Anhängen, die beide den Namen des Betreffs tragen und die Dateiendung “dat“. Öffne ich diese Anhänge mit Wordpad, sehe ich jeweils meinen formatierten Text.
Dann habe ich mich mit folgender Funktion (gefunden in einem Forum) am html-Versand versucht:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78:
| function MeinMailVersand(const aAbsender, aMailCopyTo, aUserName, aHost, aPassword, aEmpfaenger, aSubject, aTextBody, aHtmlBody, aDateianlage: string; var aMsg: string) : boolean; var Html: TStrings; HtmPart, TxtPart: TIdText; SMTP: TIdSMTP; BmpPart: TIdAttachmentFile; EMail: TIdMessage; begin aMsg := ''; Result := false; EMail := nil; Html := nil; SMTP := nil; try SMTP := TIdSMTP.Create; Html := TStringList.Create; EMail := TIdMessage.Create(nil); Html.Add('<html>'); Html.Add('<head>'); Html.Add('</head>'); Html.Add('<body>'+aHtmlBody); Html.Add('</body>'); Html.Add('</html>'); EMail.From.Address := aAbsender; EMail.Recipients.EMailAddresses := aEmpfaenger; EMail.Subject := aSubject; EMail.ContentType := 'multipart/mixed'; EMail.Body.Assign(Html); if aTextBody <> '' then begin TxtPart := TIdText.Create(email.MessageParts); TxtPart.ContentType := 'text/plain'; TxtPart.Body.Text := aTextBody; end; if aDateianlage <> '' then begin HtmPart := TIdText.Create(email.MessageParts, html); HtmPart.ContentType := 'text/html'; BmpPart := TIdAttachmentFile.Create(EMail.MessageParts, aDateianlage); BmpPart.ContentType := 'image/jpeg'; BmpPart.ContentDisposition := 'inline'; BmpPart.ExtraHeaders.Values['content-id'] := 'us.jpg'; BmpPart.DisplayName := 'us.jpg'; end; SMTP.Username := aUserName; SMTP.Host := aHost; SMTP.Password := aPassword; try SMTP.Connect; try SMTP.Send(EMail); if aMailCopyTo <> '' then begin EMail.Subject := '[Kopie E-Mail an ' + aEmpfaenger+ '] - ' + EMail.Subject; EMail.Recipients.EMailAddresses := aAbsender; EMail.ExtraHeaders.Clear; SMTP.Send(EMail); end; aMsg := 'E-Mail an <'+aEmpfaenger+'> erfolgreich gesendet um ' + DateTimeToStr(Now); Result := True; except on E: Exception do aMsg := 'Fehler beim Mail-Versand: ' + E.Message; end; finally SMTP.Disconnect; end; finally EMail.Free; Html.Free; SMTP.Free; end; end; |
Im Web-Client sehe ich das, was ich für aTextBody an die Funktion übergebe von dem, was ich als aHtmlBody übergebe, sehe ich nichts. Es gibt dort auch keinen Anhang.
In Outlook wird der html-Quelltext angezeigt:
HTML-Dokument
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| <html> <head> </head> <body>Hallo<br>
<p align="center"><b><h2>Hallo</h 2></b></p>
</body> </html> |
Vorstehende Zeilen stehen in einem Memo-Feld: Diese Zeilen habe ich als aHtmlBody an die Funktion übergeben.
Mit diesen Ergebnissen habe ich meine Versuche Mitte April beendet. Jetzt bin ich soweit, dass alles andere läuft, Serienmails, Rundmails, aber eben ohne Formatierung.
Gruß
Gagga