+ Start a Discussion
Starz26Starz26 

Ever need the ability to use an email service address as an Org Default Email Address

Neat little trick in case you need it:

 

1. Create the class for the Inbound Email Handler:

 

 

global class myHandler implements Messaging.InboundEmailHandler {
      global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
          Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
          
          
          if(email.htmlBody.contains('We have received the following request to add this'))
              sendVerificationEmail(email, 'YOUR EMAIL ADDRESS HERE');
          
          
          return result;
      }

    
    private void sendVerificationEmail(Messaging.InboundEmail email, String toAddress){
    
    
        Messaging.reserveSingleEmailCapacity(1);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {toAddress};

        
        mail.setToAddresses(toAddresses);
        mail.setSenderDisplayName('WHATEVER YOU WANT HERE');

        mail.setSubject('WHATEVER YOU WANT HERE');
        mail.setPlainTextBody(email.plainTextBody);
        mail.setHtmlBody(email.htmlBody);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    
    
    }

  }

 

2. Create the email service

3. Copy the email service address

4. Create a new Org Default Email Addres using the address from the email service

5. It will send the confirmation email to the email handler which will forward it on to the email address you specified so you can click the link to verify

6. Now you can use the address in workflows.

 

Why would you want to do this:

 

** So you can send email notifications to addresses using workflow so you do not have issues with gov limits. The email can be replied to and then you can proccess the reply (Like in a custom approval process).

 

 

 

Huang ZhigangHuang Zhigang
Starz26, Thanks for your post, it is really a big suprise for me, make me alive again.