0
votes

I'm currently trying to configure Mail2Bug to create Bugs in Azure DevOps when new emails arrive in a shared mailbox. Everything was going well until the part where it needs to reply to the incoming message.

The code which handles this function can be found in EWSIncomingMessage.cs:

 public void Reply(string replyHtml, bool replyAll)
 {
     //_message is of type EmailMessage
     var reply = _message.CreateReply(replyAll);
     reply.BodyPrefix = new MessageBody(BodyType.HTML, replyHtml);
     reply.Send();
 }

Instead of replying using the shared mailbox's email, it uses the one from the authenticated user. I'm assuming this has to do with how CreateReply populates the reply MailMessage in combination with EWS.

Are there any ways around this (possibly by creating a new MailMessage and simulate a reply)?

1

1 Answers

2
votes

You could refer to the below code:

var message = (EmailMessage) Item.Bind(service, new ItemId(uniqueId), PropertySet.FirstClassProperties);
var reply = message.CreateReply(false);
reply.BodyPrefix = "Response text goes here";
var replyMessage = reply.Save(WellKnownFolderName.Drafts);
replyMessage.Attachments.AddFileAttachment("d:\\inbox\\test.pdf");
replyMessage.Update(ConflictResolutionMode.AlwaysOverwrite);
replyMessage.SendAndSaveCopy();

For more information, please refer to these links:

Replying with attachments to an email message with EWS

How to reply to an email using the EWS Managed API?

Respond to email messages by using EWS in Exchange