我需要通过EWS将电子邮件发送到Microsoft Exchange服务器。即使在代理和本地环境下,它也可以正常工作。但是不知何故它无法进行生产。请检查以下异常。
我交叉检查了是否在环境中打开了所有端口。
我准备了一个小程序来获取异常。请在下面找到代码。身份验证没有问题。所有提供的值都是正确的。 此外,在生产环境中也未启用代理。
public class emailTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out
.println("******************Inside emailTest*************************");
try {
Properties prop = new Properties();
InputStream input = null;
input = new FileInputStream("config.properties");
prop.load(input);
String userName = "xxxxx@xxx.com";
String passWord = "xxxxx";
String domain = "domain.com";
String proxyName = "PROXYNAME";
String proxyport = "PROXYPORT";
String url = "https://outlook.office365.com/EWS/Exchange.asmx";
String tolist = "xxxxx@xxx.com";
String from = "xxxxx@xxx.com";
String ccList = "xxxxx@xxx.com";
System.out.println("Initailizing credentials");
if (userName != null && passWord != null && domain != null) {
ExchangeCredentials credentials = new WebCredentials(
userName, passWord);
ExchangeService service = new ExchangeService(
ExchangeVersion.Exchange2010_SP2);
System.out.println("Initializing Service ");
System.out.println("Setting credentials");
service.setUseDefaultCredentials(true);
service.setCredentials(credentials);
if (proxyName != null) {
WebProxy WebRequest = new WebProxy(proxyName,
Integer.parseInt(proxyport));
service.setWebProxy(WebRequest);
}
service.setUrl(new URI(url));
// service.autodiscoverUrl("xxxx@xxx.com");
EmailMessage mail = new EmailMessage(service);
mail.setSubject("Test Mail Exchange Service");
mail.setBody(new MessageBody(
"Test Mail Exchange Service -Mail body"));
System.out.println("Adding Receipents");
for (String to : tolist.split(";")) {
mail.getToRecipients().add(new EmailAddress(to));
}
for (String cc : ccList.split(";")) {
mail.getCcRecipients().add(new EmailAddress(cc));
}
mail.setFrom(new EmailAddress(from));
System.out.println("Sending Mail ");
mail.sendAndSaveCopy();
System.out.println("Sent Successfully");
} else {
System.out.println("Please configure username,password,domain");
}
} catch (Exception e) {
System.out.println("Execption ************ " + e.toString());
e.printStackTrace();
}
}
}
请在生产环境中为我提供帮助。
答案 0 :(得分:0)
这是ews-java-api本身的错误。
有关更多信息,您可以参考以下链接:
ews-java-api java.net.ConnectException: Connection timed out for https
答案 1 :(得分:0)
尝试这种依赖性
<!-- https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.1</version>
</dependency>