hallo leute ich habe folgende Procedure zum Newsletter Mails zu versenden:
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:
| procedure sendNewsLetter(an:Tstringlist; att,Text:Tstrings; vonMail,Betreff,Priority,ContentTyp,SMTPServer,SMTPUsername,SMTPPass:String; SMTPPort,SmtpAuthType:integer);
var IdMsgSend:TidMessage; SMTP:TidSmtp; i:integer; s:string; begin IdMsgSend:=TidMessage.Create(nil); SMTP:=TidSmtp.Create(nil); with IdMsgSend do begin ContentType :=ContentTyp ; Body.Assign(Text); From.Text := vonMail; ReplyTo.EMailAddresses := vonMail; Subject := Betreff; Priority := Priority; s:=''; for i:=0 to an.Count-1 do begin s:=s+BccList.EMailAddresses+an.Strings[i]+';' end; BccList.EMailAddresses:=s; ReceiptRecipient.Text:=vonMail; end;
if att.Count>=1 then begin for i:=0 to att.Count-1 do begin TIdAttachment.Create(IdMsgSend.MessageParts, att.Strings[i] ); end; end; IdMsgSend.ContentType :=ContentTyp ;
case SmtpAuthType of 0: SMTP.AuthenticationType := atNone; 1: SMTP.AuthenticationType := atLogin; end; SMTP.Username := SMTPUsername; SMTP.Password := SMTPPass;
SMTP.Host := SMTPServer; SMTP.Port := SMTPPort;
SMTP.Connect; try SMTP.Send(IdMsgSend); finally SMTP.Disconnect; end; IdMsgSend.free; SMTP.free; end;
procedure TForm1.Button1Click(Sender: TObject); var an:Tstringlist; begin an:=Tstringlist.Create; an.Add('mr5@bluewin.ch'); sendNewsLetter(an,listbox1.items,memo1.Lines,'mr5@bluewin.ch','Test','mpnormal','text/html','mail.bluewin.ch','','',25,0); end; |
Die Procedure funktioniert soweit einwandfrei nur hab ich folgendes Problem:
Wenn ich eine html mail versenden und noch ein attachment mit schicke dann wird der html text nicht mehr dargestellt es zeigt denn nur noch den html source an. Schicke ich das selbe html mail ohne attachmet , zeigt es mir das mail korrekt an.
Ich hab auch schon die mail headers angeschaut. Wenn ein Attachmet dabi is haut er mir beim text contetn automatisch ein "Content-Type: text/plain" Bei einem Mail ohne Attachment macht er das ned und übernimmt den contetn den ich eingestellt habe Content-Type: text/html
Delphi-Quelltext
1: 2: 3: 4:
| with TIdText.Create(IdMsgSend.MessageParts, Text) do begin ContentType := ContentTyp; end; |
hab ich auch schon versucht! geht auch ned
Weiss jemand was da das Problem ist ? oder wie man erreichen kann dass html Mail mit Attachments auch richtig ankommen ?
Danke für eure Hilfe
Greetz Cyrus
Moderiert von
Tino: Code- durch Delphi-Tags ersetzt.