I wrote the below simple trigger for preventing Users from emailing as anything but the support account.

I wrote this to work for the "Send an email" Task page (when sending an email to an Opp, Lead, or Contact) but it only works for Cases.

It seems from http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_emailmessage.htm that the EmailMessage object is specifically meant for Cases but then why does it look and behave (in terms of delivering an email) the same as one-off emails?

Any ideas on how to make this apply to the regular one-off emails?

trigger PreventEmailingFromPersonalEmails on EmailMessage (before insert) {

    // EmailMessage is "An email message related to Email-to-Case."
    for(EmailMessage message: Trigger.New)
        // Check if from email address is not the approved address - IGNORE INCOMING EMAIL!
        if(message.FromAddress != 'support@myorg.com' && message.Incoming == false )
            // If not, show error
            message.addError('Trigger Alert: You must send all email as support@myorg.com');
| improve this question | | | | |

try the Task Insert trigger. Each email creates a Task record so you can do the check in the Task Before Insert trigger. If you add an error on the new Task record (addError('the message')) the user is informed the Task is not inserted and the email is not sent !

| improve this answer | | | | |
  • Hello Manos, I would love to do that but I can't figure out which conditions to throw the error. I only want to prevent the email if it is not being sent from a certain address. However no fromAddress is listed on a task. – Neverending Woes Oct 21 '13 at 14:06
  • Well the email is sent from the Users email address right ? So how about checking the Task.CreatedBy.Email ? – ManSpan Oct 21 '13 at 14:59
  • Wouldn't that just check if the User's profile email address? I don't want to disable entire Users from sending emails, only prevent them from selecting a fromAddress that is not support@myorg.com – Neverending Woes Oct 21 '13 at 15:50
  • doesn't the system set the from Address to the User's email ? That's what happens with the emails I get... – ManSpan Oct 21 '13 at 16:05
  • 1
    yes you're right... This is not recorded anywhere in the system. – ManSpan Oct 21 '13 at 16:23

It seems that the emailMessage object only supports Cases and the only way around this would be a custom visualforce page.

Source: Sonam_SFDC from Force.com boards

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.