Results 1 to 6 of 6

Thread: E-mail met image versturen

  1. #1

    E-mail met image versturen

    Ik wil graag een E-mail versturen met daarin een image direct zichtbaar, dus niet als bijlage.

    Wat moet ik aan onderstaande programmaregels veranderen om dit te bewerkstelligen?

    Code:
      MailItem1: TMailItem;
      OutlookApplication1: TOutlookApplication;
    
    
      OutlookApplication1.Connect;
      MailItem1.ConnectTo(OutlookApplication1.CreateItem(olMailItem) as MailItem);
      MailItem1.Display;
      MailItem1.Recipients.Add('voorbeeld@mail.nl') ;
      MailItem1.Subject:='Outlook Mail From Delphi';
      MailItem1.Attachments.Add('D:\image001.jpg',olEmbeddeditem,'1','Logo');
      MailItem1.HTMLBody:='<DIV align=center><IMG height=65 src="cid:Logo" width=339 align=left>Test HTML </DIV>';
      OutlookApplication1.Disconnect;

  2. #2
    We adore chaos because we like to restore order - M.C. Escher

  3. #3
    Inderdaad inline images, maar in deze voorbeelden kan ik niets vinden.

  4. #4
    Stijn Sanders develyoy's Avatar
    Join Date
    Jun 2008
    Location
    GentBrugge, Belgi?½
    Posts
    1,046
    Ik herinner me dat in de mail zelf er een verschil is tussen multipart/mixed, multipart/alternative en multipart/related. En het is van belang welke je gebruikt om beelden in HTML te tonen. Maar hoe je het nu weer precies in Indy moet doen zou ik moeten opzoeken. update even zoeken op Google geef me dit, zou dit het kunnen zijn? http://www.indyproject.org/sockets/b...080116.EN.aspx

  5. #5
    John Kuiper
    Join Date
    Apr 2007
    Location
    Almere
    Posts
    8,747
    Ik heb een project gemaakt om xml bestanden te ontvangen en te verzenden. Dit was op basis van indy10:
    delphi Code:
    1. procedure SendMail(sl : TStringlist);
    2. var TextPart   : TIDText;
    3.     Attachment : TIdAttachmentfile;
    4.     SendFile,
    5.     Body       : string;
    6.     SentMsg    : Tidmessage;
    7.     idSMTP1    : TidSMTP;
    8.     MemFile    : TStrings;
    9. begin
    10.   idSMTP1 := TidSMTP.Create(nil);
    11.   SentMsg := TIDMessage.Create(nil);
    12.   SendFile :=  settings.DirExport + '\' + sl.Values['xml'];
    13.   idSMTP1.Host := settings.SMTPhost;
    14.   if settings.SMTPUser > '' then
    15.   begin
    16.     idSMTP1.Username := settings.SMTPUser;
    17.     idSMTP1.Password := settings.SMTPWachtwoord;
    18.   end;
    19.   MemFile := TStringlist.Create;
    20. //  idSMTP1.Password:=your password;
    21.   try
    22.     with SentMsg do
    23.     begin
    24.       Clear;
    25.       IsEncoded   := True ;
    26.       CharSet     := 'iso-8859-1';
    27.       Encoding    := meMIME;
    28.       ContentType := 'multipart/mixed';
    29.       Subject     := sl.Values['bericht'] + ':' + sl.Values['leverancier'];
    30.       Body.Clear;
    31.       BccList.Clear;
    32.       //setup idmessage parameters
    33.       From.address := settings.Afzender;
    34.       Recipients.EMailAddresses := sl.Values['email'];
    35.     end;
    36.     TextPart := TIdText.Create(SentMsg.MessageParts, nil);
    37.     TextPart.ContentType := 'text/plain';
    38.     TextPart.Body.Text := '';
    39.  
    40.     Attachment := TIdAttachmentfile.Create(SentMsg.MessageParts,SendFile);
    41.     Attachment.ContentDisposition := 'attachment';
    42.     Attachment.ContentType := 'text/xml';
    43.     Attachment.FileName := ExtractFileName(SendFile);
    44.     MemFile.LoadFromFile(SendFile);
    45.     Body := MemFile.Text;
    46.     //send the message
    47.     Memo1.Lines.Add('[VERZENDEN]');
    48.     Memo1.Lines.Add(format('%-10s : %-25s',['Verzend',datetostr(Now) + ' ' + timetostr(Now)]));
    49.     Memo1.Lines.Add(format('%-10s : %-30s',['Ontvanger',SentMsg.Recipients.EMailAddresses]));
    50.     Memo1.Lines.Add(format('%-10s : %-30s',['Subject',SentMsg.Subject]));
    51.     Memo1.Lines.Add('');
    52.     try
    53.       idSMTP1.Connect;
    54.       idSMTP1.send(SentMsg);
    55.     except on E: EIdSMTPReplyError do
    56.       ShowMessage(E.Message);
    57.     end;
    58.   finally
    59.     //disconnect from server
    60.     if IdSMTP1.Connected then
    61.       IdSMTP1.Disconnect;
    62.     SaveMessage(1,0, Body, SentMsg);
    63.     Attachment.Free;
    64.     TextPart.Free;
    65.     SentMsg.Free;
    66.     idSMTP1.Free;
    67.     Memfile.free;
    68.   end;
    69. end;
    Zal voor images niet zoveel verschil zijn.
    Ik weet alleen niet hoe het zit met Outlook.
    Delphi is great. Lazarus is more powerfull

  6. #6
    Na wat experimenteren kwam ik op de volgende oplossing die voor mij voldoet:

    Code:
      MailItem1: TMailItem;
      OutlookApplication1: TOutlookApplication;
    
    
      OutlookApplication1.Connect;
      MailItem1.ConnectTo(OutlookApplication1.CreateItem(olMailItem) as MailItem);
      MailItem1.Attachments.Add('D:\image001.jpg',olEmbeddeditem,'1','Logo');
      MailItem1.Display;
      MailItem1.Recipients.Add('voorbeeld@mail.nl') ;
      MailItem1.Subject:='Outlook Mail From Delphi';
      MailItem1.HTMLBody:='<DIV align=center><IMG src="cid:image001.jpg" align=left>Test HTML </DIV>';
      OutlookApplication1.Disconnect;
    Let op! De volgorde is belangrijk.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •