0

JAVAMail API を使用して電子メールを送信しています。しかし、認証は失敗します。

サンプル入力はこちら

private String to = "junaidbinsarfraz@yahoo.com";
private String from = "juniad_rocku@yahoo.com";
private String username = "juniad_rocku";
private String password = "myactualpassword";
private String subject = "My Subject";
private String body = "Please see the attached file";

コードは

private void emailFile(){

    String host = "relay.jangosmtp.net";

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", "25");

    // Get the Session object.
    Session session = Session.getInstance(props,
       new javax.mail.Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
             return new PasswordAuthentication(username, password);
          }
       });

    try {
       Message message = new MimeMessage(session);

       message.setFrom(new InternetAddress(from));

       message.setRecipients(Message.RecipientType.TO,
          InternetAddress.parse(to));

       message.setSubject(this.subject);

       BodyPart messageBodyPart = new MimeBodyPart();

       messageBodyPart.setText(this.body);

       Multipart multipart = new MimeMultipart();

       multipart.addBodyPart(messageBodyPart);

       for(String filePath : UniversityForm.allAttachedFilesPath) {
           if(filePath != null && !(filePath.equals("")))
                this.addAttachment(multipart, filePath);
       }

       message.setContent(multipart);

       Transport.send(message);

       System.out.println("Sent message successfully....");

    } catch (MessagingException e) {
       throw new RuntimeException(e);
    }
}

エラー

java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 535 5.7.8 Authentication credentials invalid

適切なユーザー名、パスワードを指定しました...認証に失敗した理由がわかりません。についてはわかりませんhost。どこが間違っていますか?助けてください。

4

2 に答える 2

0

これがyahoo smtpの私の作業構成です。それが役立つことを願っています:

<property name="host" value="smtp.mail.yahoo.com"/>
        <property name="port" value="587 "/>
        <property name="username" value="z********e@yahoo.com"/>
        <property name="password" value="**********"/>
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.smtp.starttls.enable">true</prop>
                <prop key="mail.debug">true</prop>
            </props>
        </property>
于 2014-12-10T10:38:45.183 に答える
0

Yahoo メール サーバーは、ポート番号 465 の「smtp.mail.yahoo.com」です。「mail.password」プロパティを追加するのを忘れています。次の追加プロパティを追加する必要があります。

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.mail.yahoo.com");
props.put("mail.smtp.port", "465");
props.put("mail.transport.protocol", "smtps");
props.put("mail.password", password);
于 2014-12-07T12:06:45.133 に答える