Jump to content

mazluta

Members
  • Content Count

    31
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. you right. sorry. PngGraphic := TPngGraphic.Create; try DibGraphic := TDibGraphic.Create; try Result := Base64ToImg(Base64Str, DibGraphic, FileExtn); if not Result then Exit; PngGraphic.Assign(DibGraphic); finally DibGraphic.Free; end; if PngGraphic.Empty then Exit; did you read the TAO? it's old as the wheel of time......
  2. Thanks Remy. no doubt your code is more efficient. but on save the base64 as PNG is not the right way. the base 64 is string depend on the file type. i work with Envision https://www.intervalsoftware.com/envision.html So i load any one of the type with appropriate object and convert it all to PNG, create the PNG, load it to the Html Files of the mail body and send the mail. You are the MASTER. UDDF - Tao of Programming.mht
  3. yeeee that abug yes. you right 🙂
  4. Ok. That Work. function Tdm_Image.DoFixMailTextBody(MAIL_TextBody : String; Attach_Base64 : TStringList) : String; Var CurTry : Integer; CurPos : Integer; CurChar : Integer; UniqueNo : Integer; StartFrom : Integer; EndTo : Integer; Base64Str : String; base64 : TBase64Encoding; StrArray : TBytes; DibGraphic : TDibGraphic; TmpPNG : TPngGraphic; TestStr : String; fTempDir : String; PngFileName : String; NewImgSrc : String; FileExtn : String; begin Result := MAIL_TextBody; Attach_Base64.Clear; CurTry := 0; While CurTry < 250 Do begin CurTry := CurTry + 1; FileExtn := ''; FileExtn := 'png'; CurPos := pos(Base64_01,MAIL_TextBody); if CurPos < 1 then begin FileExtn := 'jpg'; CurPos := pos(Base64_02,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'svg'; CurPos := pos(Base64_03,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'png'; CurPos := pos(Base64_04,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'jpg'; CurPos := pos(Base64_05,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'bmp'; CurPos := pos(Base64_06,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'gif'; CurPos := pos(Base64_07,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'tif'; CurPos := pos(Base64_08,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'wmf'; CurPos := pos(Base64_09,MAIL_TextBody); end; if CurPos < 1 then begin FileExtn := 'emf'; CurPos := pos(Base64_10,MAIL_TextBody); end; if CurPos > 0 then begin UniqueNo := GetUniqueNumber; {This will be tje dic Number} StartFrom := 0; EndTo := 0; // first find the , char - after that start the base64 string For CurChar := CurPos + 5 to Length(MAIL_TextBody) Do begin if MAIL_TextBody[CurChar] = ',' then begin StartFrom := CurChar + 1; Break; end; end; // the find the next " char - this close the base64 string For CurChar := StartFrom + 5 to Length(MAIL_TextBody) Do begin if MAIL_TextBody[CurChar] = '"' then begin EndTo := CurChar - 1; Break; end; end; // take the Base64 String And Convert to png file DibGraphic := TDibGraphic.Create; Try fTempDir := RemoveBackSlashChar(RemoveSlashChar(UniServerModule.LocalCachePath)); Base64Str := Copy(MAIL_TextBody,StartFrom, EndTo - StartFrom); if Base64ToImg(Base64Str,DibGraphic, FileExtn) then begin PngFileName := fTempDir + '\' + IntToStr(UniqueNo) + '.png'; TmpPNG := TPngGraphic.Create; Try TmpPNG.Assign(DibGraphic); TmpPNG.SaveToFile(PngFileName); Attach_Base64.Add(PngFileName); Delete(MAIL_TextBody, CurPos + 5, EndTo - CurPos - 4); NewImgSrc := 'cid:' + IntToStr(UniqueNo) +'.png'; Insert(NewImgSrc, MAIL_TextBody, CurPos + 5); Finally FreeAndNil(TmpPNG); End; end; Finally FreeAndNil(DibGraphic); End; end else begin Break; end; end; Result := MAIL_TextBody; end; and to send the Mail : function SendMailBySMTP(SMTP_Host : String; SMTP_User : String; SMTP_Password : String; SMTP_Port : Integer; Send_FromAddress : String; Send_FromName : String; Send_ToAddress : String; Send_ToName : String; Send_Subject : String; Send_TextBody : String; UseCid : Boolean; Attach_Base64 : TStringList; Attach_List : TStringList) : Boolean; Var cid : WideString; SMTP : TIdSMTP; AMsg : TidMessage; CurAttch : Integer; FoundBase64 : Boolean; Const Base64_01 : String = 'src="data:image/png;base64,'; Base64_02 : String = 'src="data:image/jpeg;base64,'; Base64_03 : String = 'src="data:image/image/svg+xml;base64,'; Base64_04 : String = 'src="data:image/image/apng;base64,'; Base64_05 : String = 'src="data:image/jpg;base64,'; Base64_06 : String = 'src="data:image/image/bmp;base64,'; Base64_07 : String = 'src="data:image/image/gif;base64,'; Base64_08 : String = 'src="data:image/image/tiff;base64,'; Base64_09 : String = 'src="data:image/image/wmf;base64,'; Base64_10 : String = 'src="data:image/image/emf;base64,'; begin Result := False; Try if UseCid Then begin FoundBase64 := False; if (pos(Base64_01,Send_TextBody) > 0) Or (pos(Base64_02,Send_TextBody) > 0) Or (pos(Base64_03,Send_TextBody) > 0) Or (pos(Base64_04,Send_TextBody) > 0) Or (pos(Base64_05,Send_TextBody) > 0) Or (pos(Base64_06,Send_TextBody) > 0) Or (pos(Base64_07,Send_TextBody) > 0) Or (pos(Base64_08,Send_TextBody) > 0) Or (pos(Base64_09,Send_TextBody) > 0) Or (pos(Base64_10,Send_TextBody) > 0) then FoundBase64 := True; if not FoundBase64 Then UseCid := False; end; if UseCid then begin end; Try SMTP:= TIdSMTP.Create(nil); SMTP.Disconnect(); SMTP.Host := SMTP_Host; SMTP.Username := SMTP_User; SMTP.Password := SMTP_Password; SMTP.Port := SMTP_Port; AMsg := TidMessage.Create(nil); AMsg.Encoding := meDefault; AMsg.ContentType := 'text/html'; if Attach_List.Count > 0 then AMsg.ContentType := 'multipart/mixed'; AMsg.CharSet := 'UTF-8'; //AMsg.ContentTransferEncoding := '8bit'; AMsg.subject := UTF8Encode(Send_Subject); AMsg.From.Name := UTF8Encode(Send_FromName); AMsg.From.Address := Send_FromAddress; with AMsg.Recipients.Add do begin Name := UTF8Encode(Send_ToName); Address := Send_ToAddress; end; with TIdMessageBuilderHtml.Create do try HtmlCharSet := 'UTF-8'; Html.Text := UTF8Encode(Send_TextBody); if Attach_List.Count > 0 then begin for CurAttch := 0 To Attach_List.Count - 1 Do begin Attachments.Add(Attach_List.Strings[CurAttch]); end; end; if Attach_Base64.Count > 0 then begin for CurAttch := 0 To Attach_Base64.Count - 1 Do begin HtmlFiles.Add(Attach_Base64.Strings[CurAttch]); end; end; FillMessage(AMsg); finally Free; end; SMTP.Connect; SMTP.Send(AMsg); Result := True; Finally AMsg.Free; SMTP.Disconnect; SMTP.Free; End; Except on E: Exception do begin AddMsgToEventLog('', J_FirstFileName(ParamStr(0)), 'Fail send SMPT Mail, Error :' + e.Message,EVENTLOG_ERROR_TYPE, 4, 1); Result := False; end; End; end; function IsTherBase64InHTML(HTML_Text : String) : Boolean; Const Base64_01 : String = 'src="data:image/png;base64,'; Base64_02 : String = 'src="data:image/jpeg;base64,'; Base64_03 : String = 'src="data:image/image/svg+xml;base64,'; Base64_04 : String = 'src="data:image/image/apng;base64,'; Base64_05 : String = 'src="data:image/jpg;base64,'; Base64_06 : String = 'src="data:image/image/bmp;base64,'; Base64_07 : String = 'src="data:image/image/gif;base64,'; Base64_08 : String = 'src="data:image/image/tiff;base64,'; Base64_09 : String = 'src="data:image/image/wmf;base64,'; Base64_10 : String = 'src="data:image/image/emf;base64,'; begin Result := (pos(Base64_01,HTML_Text) > 0) Or (pos(Base64_02,HTML_Text) > 0) Or (pos(Base64_03,HTML_Text) > 0) Or (pos(Base64_04,HTML_Text) > 0) Or (pos(Base64_05,HTML_Text) > 0) Or (pos(Base64_06,HTML_Text) > 0) Or (pos(Base64_07,HTML_Text) > 0) Or (pos(Base64_08,HTML_Text) > 0) Or (pos(Base64_09,HTML_Text) > 0) Or (pos(Base64_10,HTML_Text) > 0); end; thanks Remy for your Help.
  5. Thanks. i will try it
  6. i see i can build the eMail for Gmail using IDMessage. i can iterate in all base64 img convert them to png file but i dont see way to embedded the image it self into the html message back...
  7. ok. now there is new problem. Gmail want show message with image base on base64 string. is there simple convert outlook message to Gmail Message?
  8. that work. 1. i remove the html conflict. 2. i gat the return string from the CkEditor. 3. i build simple HTML with 2 function. one to iterate all image. and for each <img> element i convert the base64 to be the same as the attribute (second function). 4. now, when i send the - "message" - its all look "normal".. thank Remy and Alexander. BTW - attach is the HTML file i build to convert the Images mtTag_11197140.html
  9. Thanks Alexander. i'm checking it all now.
  10. Hi Remy Thanks for you detailed answers. i see your point. i will check it all and get back to you
  11. Hi Remy Thanks for your answers. 1. What versions of Delphi and Indy are you using? delphi 10.3 + indy 10 2. Did you compare the HTML that Outlook has to the HTML that you sent? yes they are the same. 3. the msg file was just to let those how answer to see what i get. 4. why are you UTF-8 encoding. because of the Hebrew characters. 5. Your HTML has conflicting charsets in its <meta> elements. what are the conflicts? 6. the 'body' is result of CkEditor. and i don't want to change there components. and the <IMG> is most likely the Company logo. maybe if i change the base64 to the size of the style - it will work.
  12. i tried but with no help. it's look like outlook does what he want.... myTest-2.msg
  13. Hi, i'm using TIdMessageBuilderHtml to build the message body from HTML, the base HTML is Attach - myMail.html. it's Base64 + some CSS - style="height:144px; width:120px; when open this HTML with browser all look fine. after sending this with the SMPT protocol the size of the image become the TRUE SIZE of the image. and this is not what i want. myMail.msg is the email as received in my outlook. how can i fix it? uSendSMTPMail.pas myMail.html MyMail.msg
  14. Thanks Remy, I Will try the binary data and the JSON way.
  15. Hi Remy. First: thanks for the knowledge. Secondly: the "DevApp" field was sent as C# from the start. Third: the line - content = Uri.EscapeDataString(content); fix it all put "%2B" as replaced for any "+" sign and the Delphi Rest got the '+' sign as it should be without doing anything in the service. Fourth: when i sent the Base64 string back with '+' sign in the response the C# read it well and saved the PDF to wherever it should be saved.
×