I'm sending emails like this:
Messaging.SingleEmailMessage m = new Messaging.SingleEmailMessage();
m.setToAddresses( new String[]{'[email protected]'} );
m.setSubject( 'test' );
m.setHtmlBody( '...' );
m.setWhatId( anyObjectId );
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(cv.Title);
efa.setBody( pdfBlob );
efa.setContentType('application/pdf'); // does not work: (cv.FileType);
efa.setInline(false);
m.setFileAttachments( new Messaging.EmailFileAttachment[]{ efa });
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { m });
Now this perfectly work and the sent email shows up at the record with anyObjectId in the activity tab.
It even shows the paper-clip icon for the attachment. Only that the attachment itself is not visible:
It should look like this (created by sending an email OUT using the LEX UI):
I'm pretty sure that there is a ContentDocument, ContentVersion and a ContentDocumentLink (aka "Share") missing. Looking at the ContentDocument records of emails sent via the LEX-UI it should look like:
Now I would gladly manually add the missing ContentDocument, ContentVersion and a ContentDocumentLink, but only I can't because I can't get the Id of the EmailMessage as described in this question: How to get the Id of an EmailMessage after sending a SingleEmailMessage with Messaging.SendEmail()?
Any ideas on how to solve this?