Reply and Forward with full information

When you use message.Reply() or message.Forward() you are unable to add extra information, like recipients, attachments etc.., in order to workaround you must use the CraeteReply() and CreateForward() methods.

You will need the GetBind() method in order to use this code

REPLY

/// Replies the message. 
/// <param name="messId">The mess id.</param>
/// <param name="body">The body.</param>
/// <param name="replyAll">if set to <c>true</c> [reply all].</param>
/// <returns></returns>
private bool ReplyMessageCreate(string messId, string body, bool replyAll)

{
   
ExchangeService service = GetBinding();

    try
   
{
       
Item mess = Item.Bind(service, messId);
       
EmailMessage message = mess as EmailMessage;
       
if (message != null)
       
{
           
ResponseMessage reply = message.CreateReply(replyAll);
           
reply.BodyPrefix = body;

            EmailMessage replyMessage = reply.Save(WellKnownFolderName.Drafts);
           
foreach (string item in YourRecipients)
           
{
               
replyMessage.ToRecipients.Add(item);
           
}

            foreach (string item in YourRecipients)
           
{
               
replyMessage.CcRecipients.Add(item);
           
}

            foreach (string item in YourRecipients)
           
{
               
replyMessage.BccRecipients.Add(item);
           
}

            replyMessage.Attachments.AddFileAttachment(c:\att.txt);
        
           
replyMessage.Update(ConflictResolutionMode.AlwaysOverwrite);
           
replyMessage.SendAndSaveCopy();
       
}

        return true;
   
}

    catch (Exception)
   
{
       
return false;
   
}
}

FORWARD

// <summary>
/// Replies the message. 
/// <param name="messId">The mess id.</param>
/// <param name="body">The body.</param>        
/// <returns></returns>
private bool ForwardMessageCreate(string messId, string body)

{
   
ExchangeService service = Bind.GetBinding(Bind._ImpersonateUser);

    try
   
{
       
Item mess = Item.Bind(service, messId);
       
EmailMessage message = mess as EmailMessage;
       
if (message != null)
       
{
           
ResponseMessage forward = message.CreateForward();
           
forward.BodyPrefix = body;

            EmailMessage forwardMessage = forward.Save(WellKnownFolderName.Drafts);
           
foreach (string item in YourRecipients)
           
{
               
forwardMessage.ToRecipients.Add(item);
           
}

            foreach (string item in YourRecipients)
           
{
               
forwardMessage.CcRecipients.Add(item);
           
}

            foreach (string item in YourRecipients)
           
{
               
forwardMessage.BccRecipients.Add(item);
           
}

            forwardMessage.Attachments.AddFileAttachment(c:\att.txt);

            forwardMessage.Update(ConflictResolutionMode.AlwaysOverwrite);
           
forwardMessage.SendAndSaveCopy();
       
}

        return true;
   
}

    catch (Exception)
   
{

        return false;
   
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s