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

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 142 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
11manish Profile Picture

11manish 119

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans