Salesforce Inbound Email Service – Capturing From Address, To Address and Subject

Salesforce Inbound Email Service – Capturing From Address, To Address and Subject

Sample code:
global class CreateEmailLog implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail( Messaging.InboundEmail email, Messaging.InboundEnvelope env ) {
   
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
           
        try {
            
            Inbound_Email__c objIE = new Inbound_Email__c();           
            objIE.Email_Body__c = email.plainTextBody;
            objIE.From_Address__c = env.fromAddress;
            objIE.To_Address__c= env.toAddress;
            objIE.Subject__c= email.Subject;
            insert objIE;   
           
        } catch ( Exception e ) {
        
            System.debug(‘Error is: ‘ + e.getMessage() );
            
        }  
         
        result.success = true;        
        return result;
        
    }
    
}

 
Output:


Leave a Reply