从邮箱发送邮件不会保存在已发送邮件中 [英] sending mails from mail box doesn't save in sent items
问题描述
我正在使用EWS读取邮箱 test@comp.com并提供服务帐户凭据以登录到交易所。该服务帐户有权访问test@comp.com,甚至有权从中发送邮件。但是当我尝试使用以下代码发送邮件时:
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();
}
}
我看不到来自测试的邮件@ comp.com
的收件人地址是我的,而我输入的地址是test@comp.com的地址。
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?
推荐答案
您需要设置保存已发送副本的文件夹的FolderId,以使其反映您的发送邮箱,例如,更改
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);
至
FolderId SentFolderForUser = new FolderId(WellKnownFolderName.SentItems, fromEmailAddress);
replymessage.sendAndSaveCopy(SentFolderForUser);
欢呼
Glen
Cheers Glen
这篇关于从邮箱发送邮件不会保存在已发送邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!