问题
I am using using EWS to read a mailbox 'test@comp.com' and give in service account credentials to log into the exchange. that service account has access to read test@comp.com and even has access to send mails from it. but when I try to send out mails using following code :
private static void sendMailviaEWS(String to, String from, String subject,
String body, List<String> attname, ExchangeService service) {
try
{
EmailMessage replymessage = new EmailMessage(service);
replymessage.setSender(new EmailAddress(from));
EmailAddress fromEmailAddress = new EmailAddress(from);
replymessage.setFrom(fromEmailAddress);
replymessage.getToRecipients().add(to);
//replymessage.setInReplyTo(recipients);
replymessage.setSubject(subject);
replymessage.setBody(new MessageBody(body));
replymessage.sendAndSaveCopy(WellKnownFolderName.SentItems);
}catch (Exception e)
{
e.printStackTrace();
}
}
I don't see the mails getting sent from test@comp.com the to address is mine and from address which I give in is that of test@comp.com
The sent mails always end up in sent items folder of my service account which i use to log into the exchange server.
Is there a way to achieve what I want to?
回答1:
You need to set the FolderId of the folder your saving the sent copy to so it reflects the Mailbox your sending as eg change
replymessage.sendAndSaveCopy(WellKnownFolderName.SentItems);
to
FolderId SentFolderForUser = new FolderId(WellKnownFolderName.SentItems, fromEmailAddress);
replymessage.sendAndSaveCopy(SentFolderForUser);
Cheers Glen
来源:https://stackoverflow.com/questions/26121609/sending-mails-from-mail-box-doesnt-save-in-sent-items