{"id":2546,"date":"2012-01-11T00:11:02","date_gmt":"2012-01-10T18:41:02","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=2546"},"modified":"2012-01-11T00:11:02","modified_gmt":"2012-01-10T18:41:02","slug":"email-services-in-salesforce-with-simple-example","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/email-services-in-salesforce-with-simple-example\/","title":{"rendered":"Email Services in Salesforce with simple example"},"content":{"rendered":"<p><strong>What is an Email service in Salesforce?<\/strong><\/p>\n<p>Email services are automated processes that use Apex classes to process the contents, headers, and attachments of inbound email.<\/p>\n<p>You can associate each email service with one or more Salesforce-generated email addresses to which users can send messages for processing.<br \/>\nThe general template to create the apex class for the email services is:<\/p>\n<figure id=\"attachment_2548\" aria-describedby=\"caption-attachment-2548\" style=\"width: 419px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/12\/Email-Services-in-Salesforce.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\" wp-image-2548 \" title=\"How Email Services works in Salesforce\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/12\/Email-Services-in-Salesforce.png?resize=419%2C316&#038;ssl=1\" alt=\"How Email Services works in Salesforce\" width=\"419\" height=\"316\" \/><\/a><figcaption id=\"caption-attachment-2548\" class=\"wp-caption-text\">How Email Services works in Salesforce<\/figcaption><\/figure>\n<p><!--more--><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nglobal class myHandler implements Messaging.InboundEmailHandler {\n\t  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {\n\t\t  Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();\n          return result;\n      }\n  }\n<\/pre>\n<p><strong>Example of Email Service \u2013 Creating Contact from email<\/strong><br \/>\nPresumption \u2013<\/p>\n<ul>\n<li>Subject should contain word &#8220;Create Contact&#8221;\u009d<\/li>\n<li>Body contains only Contact Name.<\/li>\n<\/ul>\n<p>Apex Code with test method:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/**\n * Email services are automated processes that use Apex classes\n * to process the contents, headers, and attachments of inbound\n * email.\n *\/\nglobal class CreateContactFrmEmail implements Messaging.InboundEmailHandler {\n\n    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,\n    Messaging.InboundEnvelope envelope) {\n\n        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();\n\n\t\tString subToCompare = 'Create Contact';\n\n\t\tif(email.subject.equalsIgnoreCase(subToCompare))\n\t\t{\n\t\t\tContact c = new Contact();\n\t\t\tc.LastName = email.plainTextBody;\n\t\t\tinsert c;\n\n                \/\/ Save attachments, if any\n        \tfor (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {\n          \tAttachment attachment = new Attachment();\n\n          \tattachment.Name = tAttachment.fileName;\n          \tattachment.Body = Blob.valueOf(tAttachment.body);\n          \tattachment.ParentId = c.Id;\n          \tinsert attachment;\n        \t}\n\n        \t\/\/Save any Binary Attachment\n        \tfor (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {\n          \tAttachment attachment = new Attachment();\n\n          \tattachment.Name = bAttachment.fileName;\n          \tattachment.Body = bAttachment.body;\n          \tattachment.ParentId = c.Id;\n          \tinsert attachment;\n        \t}\n\t\t}\n\n\tresult.success = true;\n        return result;\n    }\n\n    static testMethod void testCreateContactFrmEmail() {\n    \tMessaging.InboundEmail email = new Messaging.InboundEmail() ;\n        Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();\n\n        email.subject = 'Create Contact';\n        email.plainTextBody = 'FromEmail';\n        env.fromAddress = 'ilovenagpur@gmail.com';\n\n        CreateContactFrmEmail creatC = new CreateContactFrmEmail();\n        creatC.handleInboundEmail(email, env );\n    }\n}\n\n<\/pre>\n<p>After creating the above Apex class, click <strong>Your Name | Setup | Develop | Email Services<\/strong>.<\/p>\n<ul>\n<li>Click New Email Service to define a new email service.<\/li>\n<li>Select above apex class, add email address from where to accept the request and activate the service.<\/li>\n<\/ul>\n<figure id=\"attachment_2607\" aria-describedby=\"caption-attachment-2607\" style=\"width: 428px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/01\/Email-Service-Information.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\" wp-image-2607 \" title=\"Email Service Information - Salesforce\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/01\/Email-Service-Information.png?resize=428%2C279&#038;ssl=1\" alt=\"Email Service Information - Salesforce\" width=\"428\" height=\"279\" \/><\/a><figcaption id=\"caption-attachment-2607\" class=\"wp-caption-text\">Email Service Information - Salesforce<\/figcaption><\/figure>\n<p>After filling the form, click on &#8220;Save and New Email Address&#8221;\u009d<\/p>\n<figure id=\"attachment_2608\" aria-describedby=\"caption-attachment-2608\" style=\"width: 420px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/01\/Email-Address-Information-Salesforce.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\" wp-image-2608 \" title=\"Email Address Information - Salesforce\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/01\/Email-Address-Information-Salesforce.png?resize=420%2C287&#038;ssl=1\" alt=\"Email Address Information - Salesforce\" width=\"420\" height=\"287\" \/><\/a><figcaption id=\"caption-attachment-2608\" class=\"wp-caption-text\">Email Address Information - Salesforce<\/figcaption><\/figure>\n<p><strong>Note:<\/strong> The domain name in Email address must qualify the domain name entered at &#8220;email services&#8221;\u009d in first step. For example : we have entered &#8220;gmail.com&#8221;\u009d in first step that means it will accept the email address only from the gmail.com and that&#8217;s why in second step I have used email address displayed in screen shot.<br \/>\nAfter all the above steps, one email address is generated by the salesforce. Send the email to that address with subject line &#8220;Create Contact&#8221;\u009d and contact name in email body.<br \/>\nIn the above tutorial, I have used very simple example just to demonstrate that how the email services works in the salesforce.<\/p>\n<p><strong>Governance limit of Email services in salesforce:<\/strong><br \/>\nSalesforce limits the total number of messages that all email services combined, including On-Demand Email-to-Case, can process daily. Messages that exceed this limit are bounced, discarded, or queued for processing the next day, depending on how you configure the failure response settings for each email service. Salesforce calculates the limit by multiplying the number of user licenses by 1,000, up to a daily maximum of 1,000,000<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Complete tutorial of Email services in Salesforce with simple step by step example<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,23,24,9],"tags":[337,331],"class_list":["post-2546","post","type-post","status-publish","format-standard","hentry","category-apex","category-configuration","category-force-com","category-salesforce","tag-apex","tag-salesforce"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":4516,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/login-to-salesforce-from-salesforce-using-authentication-provider\/","url_meta":{"origin":2546,"position":0},"title":"Login to Salesforce from Salesforce using Authentication Provider","author":"Jitendra","date":"May 29, 2015","format":false,"excerpt":"There are many ways to login to your Salesforce instance, using Google, Facebook, Linked, Twitter and even from other Salesforce Organization. I am sure many of readers has multiple Salesforce instances and its hard to remember password of each. We can connect every Salesforce instances and login using only one.\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce My Domain Login page","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/05\/Salesforce-My-Domain-Login-page.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2445,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/create-a-custom-web-service-in-salesforce-and-consume-it-in-c-net-application\/","url_meta":{"origin":2546,"position":1},"title":"Create a custom Web service in Salesforce and consume it in C#.Net application","author":"Jitendra","date":"September 23, 2011","format":false,"excerpt":"In this tutorial, we will create the web service in salesforce and consume it in c#.Net application","rel":"","context":"In &quot;c#&quot;","block_context":{"text":"c#","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/csharp\/"},"img":{"alt_text":"Create Custom web service in salesforce using apex and consume using C#.Net","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/09\/Create-Custom-web-service-in-salesforce-using-apex-and-consume-using-C.Net_.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":6152,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/call-salesforce-rest-api-from-apex\/","url_meta":{"origin":2546,"position":2},"title":"Call Salesforce REST API from Apex","author":"Jitendra","date":"February 27, 2014","format":false,"excerpt":"Use Apex to call Salesforce REST API with sample source code","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3537,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/consuming-external-webservice-in-apex\/","url_meta":{"origin":2546,"position":3},"title":"Consuming External Web Service in Apex &#8211; Salesforce","author":"Jitendra","date":"October 13, 2013","format":false,"excerpt":"One of the feature we have in Salesforce is that we can easily consume External Web Services. In this article, we will learn step by step demo of consuming Web Service in Apex. There are many public websites available to consume Web Service and one of them, I am using\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Generating Apex from WSDL in Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/Generating-Apex-from-WSDL-in-Salesforce-1024x345.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/Generating-Apex-from-WSDL-in-Salesforce-1024x345.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/Generating-Apex-from-WSDL-in-Salesforce-1024x345.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":6401,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/implementing-custom-apex-adapter-for-salesforce-connect\/","url_meta":{"origin":2546,"position":4},"title":"Implementing Custom Apex Adapter for Salesforce Connect","author":"Jitendra","date":"March 1, 2018","format":false,"excerpt":"Complete Source code and demo of implementing Custom Apex Adapter for Salesforce Connect","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Custom Apex Adapter for Salesforce Connect","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Custom-Apex-Adapter-for-Salesforce-Connect.png?fit=1053%2C607&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Custom-Apex-Adapter-for-Salesforce-Connect.png?fit=1053%2C607&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Custom-Apex-Adapter-for-Salesforce-Connect.png?fit=1053%2C607&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Custom-Apex-Adapter-for-Salesforce-Connect.png?fit=1053%2C607&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Custom-Apex-Adapter-for-Salesforce-Connect.png?fit=1053%2C607&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":2499,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/getting-started-with-apex-debug-logs-in-salesforce\/","url_meta":{"origin":2546,"position":5},"title":"Getting started with Apex debug logs in salesforce","author":"Jitendra","date":"November 26, 2011","format":false,"excerpt":"Introduction to debug logs in salesforce with step by step procedure and screenshot, Difference between Debug log and System log in Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Debug Logs in Monitoring section of Administration setup - salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/11\/Debug-Logs-in-Monitoring-section-of-Administration-setup-salesforce.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=2546"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2546\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=2546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=2546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=2546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}