I'm writing a program that has auto response in it. i.e. for example there is an user ad his email address would be user@domain.com
, when ever someone writes an email to this address, there should be an auto response sent (Which I'm able to do it). but this should be sent from autoReply@domain.com
(this is what I'm unable to know on how to do this). autoReply@domain.com
is a shared mail box.
I'm using ews in my program and the below block of code is responsible to send the auto response.
private void replyToEmailWithURLs(ItemId itemId, List matchedKeyWords, String fromAddress) throws Exception {
EmailMessage message = EmailMessage.bind(service, itemId, new PropertySet(BasePropertySet.IdOnly));
ResponseMessage responseMessage = message.createReply(false);
message.getReplyTo().add(new EmailAddress("autoReply@domain.com"));
// Add autoReply in CC
responseMessage.getCcRecipients().add("autoReply@domain.com");
String responseUrls = getTheResponseUrlsFromJsonFile(matchedKeyWords, fromAddress);
responseMessage.setBodyPrefix(new MessageBody(BodyType.HTML, responseUrls));
responseMessage.sendAndSaveCopy();
message.setIsRead(true);
}
Here I tried to add a replyTo using message.getReplyTo().add(new EmailAddress("autoReply@domain.com"));
, even this doesn't work.
I've seen a post here set reply-to address in outgoing email EWS , I was confused on the way it is working(basically given in c#), please let me know how can I get this done in Java.
Thanks