web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

capture email domain from email address?

(1) ShareShare
ReportReport
Posted on by 15

Hey all,

Thought this would be super simple but I am running into some walls. Any help would be appreciated:

Requirement:

  • Pull the domain from the contact email address and populate to a field on the contact form.

Background:

  • We are a membership based organization.
  • Membership is at the Account level and passed down to the contacts connected to the Account.
  • Sometimes we get contacts signing up and need to Our Accounts hold membership that pass down to the employees in that Account. We have approved domains and want to quickly identify contacts who have a member email domain. 

Thanks for taking the time to help me resolve this issue. Any thoughts would be helpful. So here goes:

I have the same question (0)
  • Suggested answer
    Charan Raju C R Profile Picture
    7 Moderator on at

    Hi Anthony,

    You can register a plugin on pre-create and pre-update of contact record which extracts domain name from email address and set to another field in contact.

    Below code is for your reference

    using System.Net.Mail;
    
    public void Execute(IServiceProvider serviceProvider)
    {
        IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    
        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
        {
            Entity entity = (Entity)context.InputParameters["Target"];
            if (entity.LogicalName.Equals("contact"))
            {
                string emailAddress = entity.Contains("emailaddress1") ? entity.GetAttributeValue("emailaddress1") : string.Empty;
                if (string.IsNullOrEmpty(emailAddress))
                {
                    MailAddress address = new MailAddress("xyz@dynamics.com");
                    string host = address.Host;
                    entity.Attributes["new_emaildomain"] = host;
                }
            }
        }
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans