简体   繁体   English

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

[英]Android JavaMail send mail with Exchange server

I'm trying to send an email using my company server but something doesn't work. 我正在尝试使用公司的服务器发送电子邮件,但无法正常工作。

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;

}

The debug shows the following: 调试显示以下内容:

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

Keeps trying to connect and doesn't give any answer. 一直尝试连接,但未给出任何答案。 When I set the mail.smtps.writetimeout it returns me java.net.SocketException: Socket closed 当我设置mail.smtps.writetimeout时,它返回给我java.net.SocketException:套接字已关闭

Any idea? 任何想法? :S :S

Keep noted that all Outlook clients use either MAPI or MAPI-over-http (MAC used EWS). 请注意,所有Outlook客户端都使用MAPI或基于HTTP的MAPI(MAC使用的EWS)。 Therefore most Exchange administrators might not have allowed users to use SMTP and therefore it might not be working as you expect. 因此,大多数Exchange管理员可能不允许用户使用SMTP,因此它可能无法按预期工作。

Did you checked with your MS Exchange administrator if you can use SMTP via that way? 您是否已与MS Exchange管理员确认是否可以通过SMTP使用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM