Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.setToAddresses(new String[] { '邮件地址'});
List<ContentDocumentLink> linklist = new List<ContentDocumentLink>();
linklist =[SELECT Id,LinkedEntityId,ContentDocumentId, ContentDocument.LatestPublishedVersion.VersionData FROM ContentDocumentLink WHERE LinkedEntityId = 'a0pp0000002Dq5kAAC'];
Set<String>IdSet = new Set<String>();
for(ContentDocumentLink cond :linklist)
{
IdSet.add(cond.ContentDocumentId);
}
List<ContentVersion> files = [SELECT title,FileType,PathOnClient,ContentSize,VersionData FROM ContentVersion WHERE ContentDocumentId in :IdSet];
List<Messaging.EmailFileAttachment> attachments = new List<Messaging.EmailFileAttachment>();
for (ContentVersion file: files)
{
System.debug(file.VersionData);
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(file.PathOnClient);
efa.setBody(file.VersionData);
// efa.setContentType('jpg');
attachments.add(efa);
}
message.setFileAttachments(attachments);
message.setSubject('测试');
message.setHtmlBody('测试');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { message });