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
Zoom_VZoom_V 

How can I forward email service email to a different address ?

I will be having email alerts sent to clients and I want their replies to go to an Email Service address. But I can't simply make that long address the "From" address because that must be an org-wide approved email address, which you cannot do with an email service address. 

So, it's been suggested to me to use an org-wide approved address (sales@company.com etc) and simply set up that email account to automatically forward all of its mail to the long email service address. However, I can't use the long email service address as a destination address in the forwarding process either. Gmail needs to send a verification to whatever email will be used and I cannot perform an approval for the email address, or at least I don't know how to.

How can I accomplish this ? 

Thank you.
Beau Gordon 6Beau Gordon 6
We do what you describe (set up a company email address and a rule to forward messages sent to that address to the Salesforce email service address).  In principle I think that's the best approach.  The difference is we are using exchange, and you can set up a server-side rule to redirect emails without verifying the destination email.

I found this about forwarding gmail without verification, but not sure if it will help you: https://support.google.com/a/answer/176605?hl=en
 
Zoom_VZoom_V

Beau - I came across this solution. Basically, when used with the Email Services it will forward the Email Service email to another legit email address with an actual inbox.

So, temporarily set this code up with the Email Service in question.

Then set up the long Email Service address as a forwarding address to whatever address you want customers to send emails to. Now when Gmail (or whoever) sends the forwarding verification notice to the Email Service address the email will get bounced to some other legit address. Then you can read the email and get the verification code and then finish setting up the long email as the forwarding address. 

Then once it's set up you can turn this class off. Problem solved.

 

global class email_Handler implements Messaging.InboundEmailHandler {

        global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {

            Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
            String attachment_body;

            //Reroute Verification Email
            if(email.plainTextBody.contains('We have received the following request to add this')){
                sendVerificationEmail(email, 'xxxxx');
                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('Test');

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

        }

    }
Pavan Kumar 1072Pavan Kumar 1072
Thanks you gave me a nice idea it works like charm!!! @Zoom_V 
Ekta Gupta 23Ekta Gupta 23
when I am using this piece of code getting below error:

Error: Compile Error: Missing return statement required return type: Messaging.InboundEmailResult at line 3 column 45