Search code examples
delphidevexpressdelphi-xe6

LMDMapiSendMail1 - send printscreen as attachment


After 'print screen' I paste the image into cxImage component.

How can I tell LMDMapiSendMail1 (from lmdinnovative) component to send the contents of the cxImage as an attachment ?


Solution

  • Since LMDMapiSendMail1 deals attachments as files, like Remy said, one must save the file first. I found a nice example of saving printscreen to file (Mike Shkolnik). Applied it to cxImage1 properties change:

    procedure TForm11.cxImage1PropertiesChange(Sender: TObject);
    var DCDesk: HDC;
    bmp: TBitmap;
    begin
    bmp := TBitmap.Create;
      bmp.Height := Screen.Height;
      bmp.Width := Screen.Width;
      DCDesk := GetWindowDC(GetDesktopWindow);
      BitBlt(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,
             DCDesk, 0, 0, SRCCOPY);
      bmp.SaveToFile('ScreenShot.bmp');
      ReleaseDC(GetDesktopWindow, DCDesk);
      bmp.Free;
    end;
    

    It saves the file in the application.exe folder. Now all thet is left to do is to tell LMDMapiSendMail1 where the file is and add it as attachment like:

    LMDMapiSendMail1.Attachment.Append('ScreenShot.bmp');

    Not very elegant but it works.

    edit: However,I simplified everything (after I pasted the pic in the cxImage1) with a button click:

    procedure TForm11.AdvGlowButton2Click(Sender: TObject);
    begin
    cxImage1.Properties.GraphicClassName:='TJPEGImage';
    cxImage1.picture.SaveToFile(extractfilepath(application.ExeName)+'picture.jpg');
    end;
    

    Then just did :

    procedure TForm11.AdvGlowButton1Click(Sender: TObject);
    Var Path: String;
    begin
    Path:= ExtractFilePath(Application.ExeName);
    LMDMapiSendMail1.Attachment.Append(Path + 'picture.jpg');
    end;
    

    Much simpler ...