Sending the content of an HTML in a mail

AitorEGAitorEG Member Posts: 342
Hi everyone,

I need to send the content of an URL into the body of an email. In the marketing setup window, I am using CU397

I've added an URL. I need to send the content located into that URL. Is this possible?

For example:
olMailItem.HTMLBody := '<a href="http://xxxxx.com/boletin/boletin.html"/a>';       //If we want to send in HTML format
olMailItem.BodyFormat := 2;
olMailItem.Display(ShowNewMailDialogOnSend);    //If we want to display outlook  dialog window
olMailItem.Send;

Of course this is not working, but, could be an approach? Or it's impossible to do this?

Thank you very much

Best Answer

  • AitorEGAitorEG Member Posts: 342
    Answer ✓
    Thanks for your answer. I've solved this issue this way:
    //descargamos el fichero HTMl de la URL
    lHttpWebRequest := lHttpWebRequest.Create(pURL);
    lHttpWebRequest.Method :='GET';
    lHttpWebRequest.KeepAlive := TRUE;
    lHttpWebRequest.AllowAutoRedirect := TRUE;
    lHttpWebRequest.UseDefaultCredentials := TRUE;
    lHttpWebRequest.Timeout := 60000;
    
    lTempBLob.INIT;
    lTempBLob.Blob.CREATEINSTREAM(lResponseInStream);
    lWebRequestHelper.GetWebResponse(lHttpWebRequest,lHttpWebResponse,lResponseInStream,lHttpStatusCode,lResponseHeaders,GUIALLOWED);
    lTempBLob.INSERT;
    lTempBLob.CALCFIELDS(Blob);
    
    lFileMgt.BLOBExport(lTempBLob,'C:\Users\Public\Documents\boletin\boletin.html',TRUE);
    
    
    MyFile.OPEN('C:\Users\Public\Documents\boletin\boletin.html');
    MyFile.CREATEINSTREAM(StreamInTest);
    WHILE NOT StreamInTest.EOS DO BEGIN
      StreamInTest.READTEXT(Buffer);
      WholeBody := WholeBody + Buffer;
    END;
    MyFile.CLOSE;
    

    Variables:
    StreamInTest	InStream		
    Buffer	Text		
    lHttpWebRequest	DotNet	System.Net.HttpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    lTempBLob	Record	TempBlob	
    lResponseInStream	InStream		
    lWebRequestHelper	Codeunit	Web Request Helper	
    lHttpWebResponse	DotNet	System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    lHttpStatusCode	DotNet	System.Net.HttpStatusCode.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    lResponseHeaders	DotNet	System.Collections.Specialized.NameValueCollection.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    lFileMgt	Codeunit	File Management
    

Answers

  • vremeni4vremeni4 Member Posts: 323
    This will work fine, the only thing you need to do is to send the full HTML version of the email in olMailItem.HTMLBody.
    e.g.
    olMailItem.HTMLBody := '<!doctype html><html lang=en><head><meta charset=utf-8><title>blah</title></head><body><p>I'm the content</p><a href="http://xxxxx.com/boletin/boletin.html"/a></body></html>'

    I hope this helps.
  • AitorEGAitorEG Member Posts: 342
    Answer ✓
    Thanks for your answer. I've solved this issue this way:
    //descargamos el fichero HTMl de la URL
    lHttpWebRequest := lHttpWebRequest.Create(pURL);
    lHttpWebRequest.Method :='GET';
    lHttpWebRequest.KeepAlive := TRUE;
    lHttpWebRequest.AllowAutoRedirect := TRUE;
    lHttpWebRequest.UseDefaultCredentials := TRUE;
    lHttpWebRequest.Timeout := 60000;
    
    lTempBLob.INIT;
    lTempBLob.Blob.CREATEINSTREAM(lResponseInStream);
    lWebRequestHelper.GetWebResponse(lHttpWebRequest,lHttpWebResponse,lResponseInStream,lHttpStatusCode,lResponseHeaders,GUIALLOWED);
    lTempBLob.INSERT;
    lTempBLob.CALCFIELDS(Blob);
    
    lFileMgt.BLOBExport(lTempBLob,'C:\Users\Public\Documents\boletin\boletin.html',TRUE);
    
    
    MyFile.OPEN('C:\Users\Public\Documents\boletin\boletin.html');
    MyFile.CREATEINSTREAM(StreamInTest);
    WHILE NOT StreamInTest.EOS DO BEGIN
      StreamInTest.READTEXT(Buffer);
      WholeBody := WholeBody + Buffer;
    END;
    MyFile.CLOSE;
    

    Variables:
    StreamInTest	InStream		
    Buffer	Text		
    lHttpWebRequest	DotNet	System.Net.HttpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    lTempBLob	Record	TempBlob	
    lResponseInStream	InStream		
    lWebRequestHelper	Codeunit	Web Request Helper	
    lHttpWebResponse	DotNet	System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    lHttpStatusCode	DotNet	System.Net.HttpStatusCode.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    lResponseHeaders	DotNet	System.Collections.Specialized.NameValueCollection.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    lFileMgt	Codeunit	File Management
    
  • AitorEGAitorEG Member Posts: 342
    Hi again,

    I've just found another problem with this...

    Is it possible to add to the body of the mail content that it's no in HTML, apparte from the already added HTML?


    Thank you very much
Sign In or Register to comment.