1

我正在使用JavaMail API,并且可以将邮件 从发送 abc@gmail.com xyz@gmail.com

现在,我想要什么:

我想从 abc@rediffmail.com 发送电子邮件到 xyz@mail.com 等 / 等等。

外发邮件服务器:smtp.rediffmail.com

端口号:25

o/p :javax.mail.AuthenticationExcepetion ,

什么改变是必要的,或者这是否可能。

4

1 回答 1

0

尝试使用此代码段更改您的 SMTP 服务器。雅虎:外发邮件服务器 (SMTP):plus.smtp.mail.yahoo.com 使用 SSL,端口:465,使用身份验证。

片段:

    Properties props = new Properties();
    props.put("mail.smtp.user", myEmail);
    props.put("mail.smtp.host", smptServer);
    props.put("mail.smtp.port", port);
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.socketFactory.port", port);
    props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");

    SecurityManager security = System.getSecurityManager();

    try {
        Authenticator auth = new autentificadorSMTP();
        Session session = Session.getInstance(props, auth);
        // session.setDebug(true);

        MimeMessage msg = new MimeMessage(session);
        msg.setText(body);
        msg.setSubject(subject);
        msg.setFrom(new InternetAddress(myEmail));
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
                toEmail));
        Transport.send(msg);
    } catch (Exception mex) {
        mex.printStackTrace();
    }

用途:

    private class authSMTP extends javax.mail.Authenticator {
    public PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(myEmail, myPass);
    }
}

希望能帮助到你!

于 2013-10-14T12:02:08.937 回答