Skip to content

Commit 3486e1f

Browse files
authored
Merge pull request #318 from delegateas/copilot/add-support-for-failed-emails
Support re-sending emails with Failed status in SendEmailRequestHandler
2 parents 10998b6 + bbb53ee commit 3486e1f

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

.nuget/nuget.exe

7.89 MB
Binary file not shown.

src/XrmMockup365/Requests/SendEmailRequestHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal class SendEmailRequestHandler : RequestHandler
1010
{
1111
const int EMAIL_STATE_COMPLETED = 1;
1212
const int EMAIL_STATUS_DRAFT = 1;
13+
const int EMAIL_STATUS_FAILED = 8;
1314
const int EMAIL_STATUS_PENDING_SEND = 6;
1415
const int EMAIL_STATUS_SENT = 3;
1516

@@ -72,9 +73,10 @@ internal override OrganizationResponse Execute(OrganizationRequest orgRequest, E
7273

7374
var email = db.GetEntity(new EntityReference("email", request.EmailId));
7475

75-
if (email.GetAttributeValue<OptionSetValue>("statuscode").Value != EMAIL_STATUS_DRAFT)
76+
var statusCode = email.GetAttributeValue<OptionSetValue>("statuscode").Value;
77+
if (statusCode != EMAIL_STATUS_DRAFT && statusCode != EMAIL_STATUS_FAILED)
7678
{
77-
throw new FaultException("Email must be in Draft status to send");
79+
throw new FaultException("Email must be in Draft or Failed status to send");
7880
}
7981

8082
if (email.GetAttributeValue<bool>("directioncode") is false)

tests/XrmMockup365Test/TestSendEmail.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,55 @@ public void TestSendEmailRequestSuccessWithUnresolvedRecipient()
147147
}
148148
}
149149

150+
[Fact]
151+
public void TestSendEmailRequestSuccessWhenEmailStatusFailed()
152+
{
153+
var contact = new Contact
154+
{
155+
FirstName = "Test",
156+
EMailAddress1 = "test@test.com"
157+
};
158+
contact.Id = orgAdminUIService.Create(contact);
159+
160+
var email = new Email
161+
{
162+
From = new ActivityParty[]
163+
{
164+
new ActivityParty
165+
{
166+
PartyId = crm.AdminUser
167+
}
168+
},
169+
To = new ActivityParty[]
170+
{
171+
new ActivityParty
172+
{
173+
PartyId = contact.ToEntityReference()
174+
}
175+
},
176+
Subject = "Test Email",
177+
StatusCode = Email_StatusCode.Failed
178+
};
179+
email.Id = orgAdminUIService.Create(email);
180+
181+
var sendEmailRequest = new SendEmailRequest
182+
{
183+
EmailId = email.Id,
184+
IssueSend = true
185+
};
186+
187+
var response = orgAdminUIService.Execute(sendEmailRequest) as SendEmailResponse;
188+
Assert.NotNull(response);
189+
Assert.Equal(email.Subject, response.Subject);
190+
191+
using (var context = new Xrm(orgAdminUIService))
192+
{
193+
var retrievedEmail = context.EmailSet.FirstOrDefault();
194+
Assert.Equal(EmailState.Completed, retrievedEmail.StateCode);
195+
Assert.Equal(Email_StatusCode.PendingSend, retrievedEmail.StatusCode);
196+
}
197+
}
198+
150199
[Fact]
151200
public void TestSendEmailRequestFailsWhenTryingToSendAgain()
152201
{

0 commit comments

Comments
 (0)