Android JavaMail使用Exchange服务器发送邮件

Android JavaMail使用Exchange服务器发送邮件,java,android,jakarta-mail,exchange-server,Java,Android,Jakarta Mail,Exchange Server,我正试图用我公司的服务器发送电子邮件,但有些东西不起作用 private Properties _setProperties() { _port = 443; _sport = 443; Properties props = (Properties) System.getProperties().clone(); props.put("mail.smtps.host", _host); props.put("mails.debug", "true")

我正试图用我公司的服务器发送电子邮件,但有些东西不起作用

private Properties _setProperties() {


    _port = 443;
    _sport = 443;
    Properties props = (Properties) System.getProperties().clone();

    props.put("mail.smtps.host", _host);
    props.put("mails.debug", "true");
    props.put("mail.smtps.auth", "true");

    props.put("mail.smtps.port", _port);
    props.put("mail.smtps.ssl.port", "true");
    props.put("mail.smtps.ssl.socketFactory.port", _sport);
    props.put("mail.smtps.ssl.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtps.ssl.socketFactory.fallback", "false");

    return props;
}

public boolean send() throws Exception {
    Properties props = _setProperties();

    _user = "email";
    _pass = "pass";

    Session session = Session.getInstance(props, this);
    session.setDebug(true);

    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(_user));
    msg.setRecipients(MimeMessage.RecipientType.TO, "mailTO");
    msg.setSubject("SUBJECT");
    msg.setSentDate(new Date());
    msg.setText("TEXT");

    // send email
    Transport transport = session.getTransport("smtps");
    transport.connect();
    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();

    return true;

}
调试将显示以下内容:

DEBUG: setDebug: JavaMail version 1.5.5

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle]

DEBUG SMTP: need username and password for authentication

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: trying to connect to host "companyServer", port 443, isSSL true
一直在尝试联系,但没有给出任何答案。当我设置mail.smtps.writetimeout时,它会返回java.net.SocketException:socketclosed


有什么想法吗请注意,所有Outlook客户端都使用MAPI或MAPI over http(MAC使用EWS)。因此,大多数Exchange管理员可能不允许用户使用SMTP,因此它可能无法按预期工作


您是否与MS Exchange管理员核实过是否可以通过这种方式使用SMTP?

修复这些问题,并确保您使用的是官方电子邮件。你说得对,我和我的Exchange管理员核对过了,我不能使用SMTP,我必须使用EWS。我尝试了[EWS android API](github.com/alipov/EWS android API),但是它给出了一个执行错误,因为没有找到一些类,比如被删除的apache。我不是一个android开发人员,但是一个很好的起点可能是感谢,但最后一次修改的日期是2015年3月9日,现在我没有库来做