How to set up Email-to-Case using Email Services in Salesforce

In the previous blog, we go through how to set up On-demand Email-to-Case. Today, we are going to set up Email-to-case using Email Services.

How to set up Email-to-Case using Email Service
  1. From Setup, Enter email-to-case in Quick Find Box and then Select Email-to-Case.
  2. Click on Edit.
  3. Now, Click on Enable Email-to-Case.
  4. Click on Notify Case Owners on New Emails Checkbox if you want to send a notification to the owners on New Emails. You can change the Default Case Owner by selecting Support Settings from Setup and then clicking on Edit.
  5. Click on Enable HTML Email if you want to display emails in HTML in case feed view and email editor.
  6. Click on the Set Case Source to Email and Save Email-to-Case attachments as Salesforce Files.
  7. Click on the Insert Thread ID in the Email Subject, Insert Thread ID in the Email Body and Place User Signatures before Email Threads.
  8. Don't Click on Enable On-Demand Service Checkbox. You can change Failure Response Settings according to you. 
  9. Click on Save.
       
Now, Open Developer Console and Create New Apex Class name as mailToCase and copy and paste below code:
Configure Email Service
  1. From Setup, Enter Email Service in Quick Find Box and then Select Email Services.
  2. Click on New Email Service.
  3. Enter Email Service Name.
  4. Select the apex class which you just created.
  5. Select All Accepted Attachments from the dropdown. 
  6. Select the Advance Email Security Settings Checkbox.
  7. Uncheck Convert Text Attachments to Binary Attachments.
  8. Select Active checkbox.
  9. Select Bounce Message in all Failure Response Actions.
  10. Check Enable Error Routing checkbox.
  11. Give an email Id in Route Error Emails to this Email Address.
       
  12. Click on New Email Address.
        
  13. Give an Email Address Name.
  14. Email Address field auto populate with the local-port of the email address.
  15. Select Active checkbox.
  16. Select Context User. This field is auto populated and selected user will be running the apex class.
  17. Enter Email address or domain name in the Accept Email From field that are authorized to send emails.
  18. Click Save.
       
  19. You get an email address generated by Salesforce. Configure the routing for this email address.
Setting Up Routing/Forwarding Rules
  1. Open gmail and Click on Manage Labels.
  2. Click on Forwarding and POP/IMAP.
  3. Click on Add a forwarding address then paste that email address and click Next.
  4. A new window pop-up to confirm the forwarding address and Click on Proceed.
  5. Open Case Tab and change the list view to All Open Cases.
  6. Open this case and copy confirmation code.
  7. Paste this confirmation code in gmail and Click on Verify.
     
       
  8. Above pop-up shows that forwarding email address is verified.
  9. Select Forward a copy of Incoming mail to and Choose Keep Mail's copy in the inbox then Click on Save Changes.
          

Test the Email Service Configuration
  1. Send an email to the configured email address.
  2. Open case tab and you see that a new case is created. Email subject is mapped to case subject, Account, Contact and Case details are auto populated and Email body is mapped to case description.
     
Support Representative can directly send the reply through mail from Salesforce. Click on Write an email and test it by sending an email. All related details is auto populated.

That's all for today! This is how we can create case from email using Email Services. Still of you have any further suggestions, thoughts, and questions, then just make sure to comment down.

Next Up, Difference between Email-to-Case and On-Demand Email-to-Case. 

Thank You!

Comments