not able to forward the mail

EmailMessage message = new EmailMessage(service);
MessageBody body= new MessageBody("Hi This is the test mail.");
EmailAddress toEmail = new EmailAddress("kishore.kolli@hma.com");
EmailAddress fromEmail = new EmailAddress("cms.899@hma.com");
message.forward(body, toEmail);


The above code throwing the exception 

Exception in thread "main" microsoft.exchange.webservices.data.InvalidOperationException: This operation can't be performed because this service object doesn't have an Id.
at microsoft.exchange.webservices.data.ServiceObject.throwIfThisIsNew(Unknown Source)
at microsoft.exchange.webservices.data.Item.internalLoad(Unknown Source)
at microsoft.exchange.webservices.data.ServiceObject.load(Unknown Source)
at com.hma.util.mailclient.exchange.ExchangeMailClient.sendMails(ExchangeMailClient.java:119)
at com.hma.util.mailclient.exchange.ExchangeMailClient.main(ExchangeMailClient.java:150)

July 4th, 2013 5:33am

Hi,

you can not forward a message if it does not already exist in your mailbox.

Something like this should work (EWS Managed API)

MessageBody body= new MessageBody("Hi This is the test mail.");
EmailAddress toEmail = new EmailAddress("kishore.kolli@hma.com");

//Get here the message you want to forward by its id

EmailMessage message  = EmailMessage.Bind(service, id);

//forward the message

message.Forward(body, toEmail);

Free Windows Admin Tool Kit Click here and download it now
July 4th, 2013 6:40am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics