function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Scott RussoScott Russo 

Forward the original email from a case, including attachment

We are looking for a way to forward the initial email related to a case, to our shared mailbox, outside of Salesforce.  Is there a way to forward that email, it's contents(including attachments) using a workflow trigger or some other automated process in Salesforce?
The email being forwarded needs to include the Case Ref ID in the subject, and have any attachments which existed in the incoming email.

GhanshyamChoudhari provided the following code, but it's not working as expected. It's generating an email, but not forwading the original email, and it's generating on every save of the case.  Is it possible to accomplish this requirement?
 
trigger emauilwithatt on Case (before insert,before update) {
for (case ca : Trigger.New){
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'XXXXX@gmail.com'};
String[] ccAddresses = new String[] {'XXXXX@gmail.com'};
mail.setToAddresses(toAddresses);
 mail.setCcAddresses(ccAddresses);
mail.setSenderDisplayName('Name');
mail.setSubject('your case number is'+ca.CaseNumber);
mail.setPlainTextBody('This is case  email body.');
   
 List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
	for (Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :ca.Id]){
	Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
	efa.setFileName(a.Name);
	efa.setBody(a.Body);
	fileAttachments.add(efa);
       }
        mail.setFileAttachments(fileAttachments);
         
       Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
 }