Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Exception while sending an email

Posted on by 130

Hi, 

I'm getting the exception as ""Attribute 'partyobjecttypecode' cannot be NULL"" 

Guid contactid = new Guid("3E0ADDAC-6B7A-E611-97ED-00155DA0EF00");
WhoAmIRequest systemUserRequest = new WhoAmIRequest();
WhoAmIResponse systemUserResponse = (WhoAmIResponse)service.Execute(systemUserRequest);
Guid _userId = systemUserResponse.UserId;

Entity from = new Entity("activityparty");
from["partyid"] = new EntityReference("systemuser", _userId).Id;
Entity to = new Entity("activityparty");
to["partyid"] = new EntityReference("contact", contactid).Id;
//new EntityReference("contact", contactid);

// Create an e-mail message.
Entity Email = new Entity("email");
Email["from"] = new Entity[] { from };
Email["to"] = new Entity[] { to };
Email["subject"] = "CRM - Test mail";
Email["description"] = "Hi ";

Guid emailId = service.Create(Email);              //Exception at this point. 

SendEmailRequest reqSendEmail = new SendEmailRequest();
reqSendEmail.EmailId = emailId;
reqSendEmail.TrackingToken = "";
reqSendEmail.IssueSend = true;
SendEmailResponse res = (SendEmailResponse)service.Execute(reqSendEmail);

1464.email.JPG

*This post is locked for comments

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
    RE: Exception while sending an email

    Please read this, it might help:

    social.microsoft.com/.../attribute-partyobjecttypecode-cannot-be-null-while-sending-email-plugin

    Let me know if it does not resolve your query

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans