none
Adding Attachments to a Reply/Reply All/Forward Message RRS feed

  • Question

  • Hello,

    Using the two examples below as a base how would I go about adding attachments to the reply email and the forwarded email?

    Create Reply method Example:

    // Create the reply response message from the original e-mail message.
    // Indicate whether the message is a reply or reply all type of reply.
    bool replyToAll = false;
    ResponseMessage responseMessage = messageToReplyTo.CreateReply(replyToAll);
    
    // Prepend the reply to the message body.
    string myReply = "This is the message body of the e-mail reply.";
    responseMessage.BodyPrefix = myReply;
    
    // Add additional recipients to the reply e-mail message.
    responseMessage.CcRecipients.Add("user4@contoso.com");
    
    // Send and save a copy of the replied e-mail mesage in the default Sent Items folder.
    responseMessage.SendAndSaveCopy();

    Create Forward Method Example
    // Create the prefixed content to add to the forwarded message body.
    string messageBodyPrefix = "This is a message that was forwarded by using the EWS Managed API";
    
    // Create the forward response message.
    ResponseMessage responseMessage = emailMessage.CreateForward();
    
    // Prepend the e-mail message body.
    responseMessage.BodyPrefix = messageBodyPrefix;
    
    // Add the recipients who are to receive the forwarded e-mail message.
    responseMessage.ToRecipients.Add("user1@contoso.com");
    responseMessage.CcRecipients.Add("user2@contoso.com");
    responseMessage.BccRecipients.Add("user3@contoso.com");
    
    // Send the forwarded e-mail message and save a copy of the message in the default Sent Items folder.
    responseMessage.SendAndSaveCopy();

    Thanks in advance
    Monday, July 18, 2011 3:40 PM

Answers

  • Hi,

    do you have the latest service pack for the Exchange server installed on the server? If not, you should probably catch up with it. If you have a fully patched system, you should probably open a case with Microsoft Product support.

    Kind regards,
    Henning

    "rbarr sandi" wrote in message news:4778fa0d-23b4-45bc-a2eb-27e46e2d380f@communitybridge.codeplex.com...

    Hello

    I have been stuck on this problem for a few days now. The Error Event below was in the Event Viewer under MSExchange Common events. Each time I attempt to reply to (or forward) an email a new instance of the event appears in the event viewer. I can't find a solution though.

    Any help would be greatly appreciated. : )

    Event ID 4999, MSExchange Common

    Watson report about to be sent to dw20.exe for process id: 5420, with parameters: E12IIS, c-RTL-AMD64, 08.01.0240.006, WS, M.E.Services, M.E.S.C.ForwardReplyUtilities.RenderDefaultUserFontMarkup, System.NotSupportedException, 7036, 08.01.0436.000.  ErrorReportingEnabled: False

    XML View of the Event:

    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
    <Provider Name="MSExchange Common" />
    <EventID Qualifiers="16388">4999</EventID>
    <Level>2</Level>
    <Task>1</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2011-07-27T13:32:13.000Z" />
    <EventRecordID>89209</EventRecordID>
    <Channel>Application</Channel>
    <Computer>server.local</Computer>
    <Security />
    </System>
    <EventData>
    <Data>5420</Data>
    <Data>E12IIS</Data>
    <Data>c-RTL-AMD64</Data>
    <Data>08.01.0240.006</Data>
    <Data>WS</Data>
    <Data>M.E.Services</Data>
    <Data>M.E.S.C.ForwardReplyUtilities.RenderDefaultUserFontMarkup</Data>
    <Data>System.NotSupportedException</Data>
    <Data>7036</Data>
    <Data>08.01.0436.000</Data>
    <Data>False</Data>
    </EventData>
    </Event>
    
    • Marked as answer by rbarr sandi Thursday, July 28, 2011 12:40 PM
    Wednesday, July 27, 2011 3:53 PM

All replies

  • Hi,

    see http://www.infinitec.de/post/2011/07/18/Replying-with-attachments-to-an-email-message-with-EWS.aspx

    Kind regards,
    Henning

    "rbarr sandi" wrote in message news:9615a70e-cde3-46fc-93af-2cab4f3976aa@communitybridge.codeplex.com...

    Hello,

    Using the two examples below as a base how would I go about adding attachments to the reply email and the forwarded email?

    Create Reply method Example:

    // Create the reply response message from the original e-mail message.
    // Indicate whether the message is a reply or reply all type of reply.
    bool replyToAll = false;
    ResponseMessage responseMessage = messageToReplyTo.CreateReply(replyToAll);
    
    // Prepend the reply to the message body.
    string myReply = "This is the message body of the e-mail reply.";
    responseMessage.BodyPrefix = myReply;
    
    // Add additional recipients to the reply e-mail message.
    responseMessage.CcRecipients.Add("user4@contoso.com");
    
    // Send and save a copy of the replied e-mail mesage in the default Sent
    Items folder.
    responseMessage.SendAndSaveCopy();

    Create Forward Method Example

    // Create the prefixed content to add to the forwarded message body.
    string messageBodyPrefix = "This is a message that was forwarded by using
    the EWS Managed API";
    
    // Create the forward response message.
    ResponseMessage responseMessage = emailMessage.CreateForward();
    
    // Prepend the e-mail message body.
    responseMessage.BodyPrefix = messageBodyPrefix;
    
    // Add the recipients who are to receive the forwarded e-mail message.
    responseMessage.ToRecipients.Add("user1@contoso.com");
    responseMessage.CcRecipients.Add("user2@contoso.com");
    responseMessage.BccRecipients.Add("user3@contoso.com");
    
    // Send the forwarded e-mail message and save a copy of the message in the
    default Sent Items folder.
    responseMessage.SendAndSaveCopy();

    Thanks in advance

    Monday, July 18, 2011 6:05 PM
  • Hello Again

    I tried modifying my code to match the code in your article. I keep getting an error: "Unexpected end of XML document".

     

    Here's the code:

         EmailMessage messageToReplyTo = EmailMessage.Bind(service, new ItemId(messageId), PropertySet.FirstClassProperties);
         bool replyToAll = false;
         ResponseMessage responseMessage = messageToReplyTo.CreateReply(replyToAll);
         if (!String.IsNullOrEmpty(to)) { responseMessage.ToRecipients.Add(new EmailAddress(to)); }
         if (!String.IsNullOrEmpty(cc)) { responseMessage.CcRecipients.Add(new EmailAddress(cc)); }
         if (!String.IsNullOrEmpty(bcc)) { responseMessage.BccRecipients.Add(new EmailAddress(bcc)); }
         responseMessage.Subject = subject;
         responseMessage.BodyPrefix = new MessageBody(BodyType.HTML, emailBody);
    
         EmailMessage responseEmailMessage = responseMessage.Save(WellKnownFolderName.Drafts);
         if (!String.IsNullOrEmpty(attachments))
         {
          List<string> attachmentValues = JSON.Deserialize<List<string>>(attachments);
          foreach (string path in attachmentValues)
          {
           responseEmailMessage.Attachments.AddFileAttachment(path);
          }
         }
    
         responseEmailMessage.Update(ConflictResolutionMode.AlwaysOverwrite);
         responseEmailMessage.SendAndSaveCopy();
    



    Tuesday, July 19, 2011 8:35 AM
  • Hi,

    in which line do you get this error?

    Kind regards,
    Henning Krause

    "rbarr sandi" wrote in message news:e5ac4960-e38b-4c3c-96a2-9d9a91777641@communitybridge.codeplex.com...

    Hello Again

    I tried modifying my code to match the code in your article. I keep getting an error: "Unexpected end of XML document".

    Here's the code:

        EmailMessage messageToReplyTo = EmailMessage.Bind(service, new
    ItemId(messageId), PropertySet.FirstClassProperties);
        bool replyToAll = false;
        ResponseMessage responseMessage =
    messageToReplyTo.CreateReply(replyToAll);
        if (!String.IsNullOrEmpty(to)) { responseMessage.ToRecipients.Add(new
    EmailAddress(to)); }
        if (!String.IsNullOrEmpty(cc)) { responseMessage.CcRecipients.Add(new
    EmailAddress(cc)); }
        if (!String.IsNullOrEmpty(bcc)) { responseMessage.BccRecipients.Add(new
    EmailAddress(bcc)); }
        responseMessage.Subject = subject;
        responseMessage.BodyPrefix = new MessageBody(BodyType.HTML, emailBody);
         EmailMessage responseEmailMessage =
    responseMessage.Save(WellKnownFolderName.Drafts);
        if (!String.IsNullOrEmpty(attachments))
        {
         List<string> attachmentValues =
    JSON.Deserialize<List<string>>(attachments);
         foreach (string path in attachmentValues)
         {
          responseEmailMessage.Attachments.AddFileAttachment(path);
         }
        }
         responseEmailMessage.Update(ConflictResolutionMode.AlwaysOverwrite);
        responseEmailMessage.SendAndSaveCopy();
    
    Tuesday, July 19, 2011 5:20 PM
  • The error occurs on the line:

     EmailMessage responseEmailMessage = responseMessage.Save(WellKnownFolderName.Drafts);

    The stacktrace:

      at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read()
       at Microsoft.Exchange.WebServices.Data.SoapFaultDetails.ParseDetailNode(EwsXmlReader reader)
       at Microsoft.Exchange.WebServices.Data.SoapFaultDetails.Parse(EwsXmlReader reader, XmlNamespace soapNamespace)
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadSoapFault(EwsServiceXmlReader reader)
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException)
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(HttpWebRequest& request)
       at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
       at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
       at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateResponseObject(ServiceObject responseObject, FolderId parentFolderId, Nullable`1 messageDisposition)
       at Microsoft.Exchange.WebServices.Data.ResponseObject`1.InternalCreate(FolderId destinationFolderId, MessageDisposition messageDisposition)
       at Microsoft.Exchange.WebServices.Data.ResponseObject`1.Save(WellKnownFolderName destinationFolderName)
       at WealthPro2.Controllers.PersonalEmailController.SendEmail(String to, String cc, String bcc, String subject, String attachments, String emailBody, String emailType, String messageId) in C:\Users\richard.barr\Documents\Visual Studio 2010\Projects\WealthPro2\WealthPro2\Controllers\PersonalControllers\PersonalEmailController.cs:line 298

    Wednesday, July 20, 2011 8:55 AM
  • Hi,

    please enable tracing on the ExchangeService instance. It seems that the server returns strange XML which the client cannot parse.

    Kind regards,
    Henning Krause

    "rbarr sandi" wrote in message news:18fed281-5acb-4488-bda4-c3939436ab9e@communitybridge.codeplex.com...

    The error occurs on the line:

    EmailMessage responseEmailMessage =
    responseMessage.Save(WellKnownFolderName.Drafts);

    The stacktrace:
      at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read()
      at Microsoft.Exchange.WebServices.Data.SoapFaultDetails.ParseDetailNode(EwsXmlReader reader)
      at Microsoft.Exchange.WebServices.Data.SoapFaultDetails.Parse(EwsXmlReader reader, XmlNamespace soapNamespace)
      at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadSoapFault(EwsServiceXmlReader reader)
      at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException)
      at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(HttpWebRequest& request)
      at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
      at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
      at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateResponseObject(ServiceObject responseObject, FolderId parentFolderId, Nullable`1 messageDisposition)
      at Microsoft.Exchange.WebServices.Data.ResponseObject`1.InternalCreate(FolderId destinationFolderId, MessageDisposition messageDisposition)
      at Microsoft.Exchange.WebServices.Data.ResponseObject`1.Save(WellKnownFolderName destinationFolderName)
      at WealthPro2.Controllers.PersonalEmailController.SendEmail(String to, String cc, String bcc, String subject, String attachments, String emailBody, String emailType, String messageId) in C:\Users\richard.barr\Documents\Visual Studio 2010\Projects\WealthPro2\WealthPro2\Controllers\PersonalControllers\PersonalEmailController.cs:line 298

    Wednesday, July 20, 2011 9:16 AM
  • The EWS Request:

     

    <Trace Tag="EwsRequest" Tid="9" Time="2011-07-20 09:50:20Z" Version="14.02.0051.000">
      <?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Header>
          <t:RequestServerVersion Version="Exchange2007_SP1" />
          <t:TimeZoneContext>
            <t:TimeZoneDefinition Id="GMT Standard Time" />
          </t:TimeZoneContext>
          <t:ExchangeImpersonation>
            <t:ConnectingSID>
              <t:PrincipalName>bob.thebuilder</t:PrincipalName>
            </t:ConnectingSID>
          </t:ExchangeImpersonation>
        </soap:Header>
        <soap:Body>
          <m:CreateItem MessageDisposition="SaveOnly">
            <m:SavedItemFolderId>
              <t:DistinguishedFolderId Id="drafts" />
            </m:SavedItemFolderId>
            <m:Items>
              <t:ReplyToItem>
                <t:Subject>Test</t:Subject>
                <t:ToRecipients>
                  <t:Mailbox>
                    <t:EmailAddress>bob.thebuilder@domain.com</t:EmailAddress>
                  </t:Mailbox>
                </t:ToRecipients>
                <t:ReferenceItemId Id="AAMkAGI2YzE3ZDJhLTEyYmEtNGU0Yi04YWJjLTBmMDJjMWJjMjMzNgBGAAAAAAAdHMBXEIkJR6Ff02Jb905+BwBm5dhbxsUVSrv+ITT2liTVABjsNdG8AABm5dhbxsUVSrv+ITT2liTVAEkR9MLkAAA=" ChangeKey="CQAAABYAAABm5dhbxsUVSrv+ITT2liTVAEkR9TCA" />
                <t:NewBodyContent BodyType="HTML">Reply</t:NewBodyContent>
              </t:ReplyToItem>
            </m:Items>
          </m:CreateItem>
        </soap:Body>
      </soap:Envelope>
    </Trace>

     

    And the EWS Response:

     

    <Trace Tag="EwsResponse" Tid="9" Time="2011-07-20 09:50:23Z" Version="14.02.0051.000">
      <?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Header>
          <t:ServerVersionInfo MajorVersion="8" MinorVersion="1" MajorBuildNumber="340" MinorBuildNumber="0" Version="Exchange2007_SP1" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" />
        </soap:Header>
        <soap:Body>
          <soap:Fault>
            <faultcode>soap:Server</faultcode>
            <faultstring>An internal server error occurred.</faultstring>
            <detail />
          </soap:Fault>
        </soap:Body>
      </soap:Envelope>
    </Trace>

     

    "An internal server error occurred"?

    Wednesday, July 20, 2011 9:55 AM
  • Hello Again

     

    It would appear that I get this Error even when I don't attach anything to the email, i.e. when the code looks like this (from the example):

                        EmailMessage messageToReplyTo = EmailMessage.Bind(service, new ItemId(messageId), PropertySet.FirstClassProperties);
                       
                        bool replyToAll = false;

                        ResponseMessage responseMessage = messageToReplyTo.CreateReply(replyToAll);

                        string myReply = "This is the message body of the e-mail reply.";
                        responseMessage.BodyPrefix = myReply;
                        responseMessage.SendAndSaveCopy();

     

    Is there a certain way that the exchange server needs to be configured? Am i missing something?

    Friday, July 22, 2011 3:25 PM
  • Hi,

    please have a look at the EventLog of the Exchange server (Application log). Maybe Exchange has logged the incident there.

    Kind regards,
    Henning Krause

    "rbarr sandi" wrote in message news:75e74568-b5e8-4724-80d8-f0840fc04c93@communitybridge.codeplex.com...

    Hello Again

    It would appear that I get this Error even when I don't attach anything to the email, i.e. when the code looks like this (from the example):
                        EmailMessage messageToReplyTo = EmailMessage.Bind(service, new ItemId(messageId), PropertySet.FirstClassProperties);
                        bool replyToAll = false;
                        ResponseMessage responseMessage = messageToReplyTo.CreateReply(replyToAll);
                        string myReply = "This is the message body of the e-mail reply.";
                       responseMessage.BodyPrefix = myReply;
                       responseMessage.SendAndSaveCopy();

    Is there a certain way that the exchange server needs to be configured? Am i missing something?

    Friday, July 22, 2011 3:27 PM
  • Hello

    I have been stuck on this problem for a few days now. The Error Event below was in the Event Viewer under MSExchange Common events. Each time I attempt to reply to (or forward) an email a new instance of the event appears in the event viewer. I can't find a solution though.

    Any help would be greatly appreciated. : )

     

    Event ID 4999, MSExchange Common

    Watson report about to be sent to dw20.exe for process id: 5420, with parameters: E12IIS, c-RTL-AMD64, 08.01.0240.006, WS, M.E.Services, M.E.S.C.ForwardReplyUtilities.RenderDefaultUserFontMarkup, System.NotSupportedException, 7036, 08.01.0436.000.  ErrorReportingEnabled: False

     

    XML View of the Event:

    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
    <Provider Name="MSExchange Common" />
    <EventID Qualifiers="16388">4999</EventID>
    <Level>2</Level>
    <Task>1</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2011-07-27T13:32:13.000Z" />
    <EventRecordID>89209</EventRecordID>
    <Channel>Application</Channel>
    <Computer>server.local</Computer>
    <Security />
    </System>
    <EventData>
    <Data>5420</Data>
    <Data>E12IIS</Data>
    <Data>c-RTL-AMD64</Data>
    <Data>08.01.0240.006</Data>
    <Data>WS</Data>
    <Data>M.E.Services</Data>
    <Data>M.E.S.C.ForwardReplyUtilities.RenderDefaultUserFontMarkup</Data>
    <Data>System.NotSupportedException</Data>
    <Data>7036</Data>
    <Data>08.01.0436.000</Data>
    <Data>False</Data>
    </EventData>
    </Event>
    



    Wednesday, July 27, 2011 3:24 PM
  • Hi,

    do you have the latest service pack for the Exchange server installed on the server? If not, you should probably catch up with it. If you have a fully patched system, you should probably open a case with Microsoft Product support.

    Kind regards,
    Henning

    "rbarr sandi" wrote in message news:4778fa0d-23b4-45bc-a2eb-27e46e2d380f@communitybridge.codeplex.com...

    Hello

    I have been stuck on this problem for a few days now. The Error Event below was in the Event Viewer under MSExchange Common events. Each time I attempt to reply to (or forward) an email a new instance of the event appears in the event viewer. I can't find a solution though.

    Any help would be greatly appreciated. : )

    Event ID 4999, MSExchange Common

    Watson report about to be sent to dw20.exe for process id: 5420, with parameters: E12IIS, c-RTL-AMD64, 08.01.0240.006, WS, M.E.Services, M.E.S.C.ForwardReplyUtilities.RenderDefaultUserFontMarkup, System.NotSupportedException, 7036, 08.01.0436.000.  ErrorReportingEnabled: False

    XML View of the Event:

    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
    <Provider Name="MSExchange Common" />
    <EventID Qualifiers="16388">4999</EventID>
    <Level>2</Level>
    <Task>1</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2011-07-27T13:32:13.000Z" />
    <EventRecordID>89209</EventRecordID>
    <Channel>Application</Channel>
    <Computer>server.local</Computer>
    <Security />
    </System>
    <EventData>
    <Data>5420</Data>
    <Data>E12IIS</Data>
    <Data>c-RTL-AMD64</Data>
    <Data>08.01.0240.006</Data>
    <Data>WS</Data>
    <Data>M.E.Services</Data>
    <Data>M.E.S.C.ForwardReplyUtilities.RenderDefaultUserFontMarkup</Data>
    <Data>System.NotSupportedException</Data>
    <Data>7036</Data>
    <Data>08.01.0436.000</Data>
    <Data>False</Data>
    </EventData>
    </Event>
    
    • Marked as answer by rbarr sandi Thursday, July 28, 2011 12:40 PM
    Wednesday, July 27, 2011 3:53 PM
  • Hello Henning

    I made sure there were no more updates available through the Windows Update service.

    The Exchange Server is currently on SP1, I wasn't sure if upgrading to SP3 would make a difference. I looked into SP2 and I didn't like the installation process of SP2 (i.e. download and use the installation tool etc.).

    I will give a try tomorrow though.

     

    How do I open a case with Microsoft Product Support? Do you have a link you could give me?

     

    Thank you for your help Henning.

     

    Wednesday, July 27, 2011 4:17 PM
  • Hi,

    have a look at this page:
    http://support.microsoft.com/common/international.aspx?RDPATH=dm;en-us;select&target=assistance

    Kind regards,
    Henning

    "rbarr sandi" wrote in message news:d12b8b66-dd4b-4b48-856e-0a9594ca0d1a@communitybridge.codeplex.com...

    Hello Henning

    I made sure there were no more updates available through the Windows Update service.

    The Exchange Server is currently on SP1, I wasn't sure if upgrading to SP3 would make a difference. I looked into SP2 and I didn't like the installation process of SP2 (i.e. download and use the installation tool etc.).

    I will give a try tomorrow though.

    How do I open a case with Microsoft Product Support? Do you have a link you could give me?

    Thank you for your help Henning.

    Wednesday, July 27, 2011 4:24 PM
  • Hi,

    Did you find a solution to this problem? I have the same problem.

    Cheers

    Monday, August 22, 2011 8:38 AM