我收到“554交易失败”回复

时间:2013-10-22 12:30:16

标签: java javamail

我正在尝试使用Java Mail框架从yahoo服务器发送邮件。

SMTP主机:“smtp.mail.yahoo.com” SMTP端口:“465”;

我收到 554交易失败响应。下面我复制了程序和回复。

程序

public class YahooSendMail 
{
    String host, port, emailid,username, password;
    Properties props = System.getProperties();
    Session l_session = null;

    public void BSendMail() {
        host = "smtp.mail.yahoo.com";
        port = "465";
        emailid = "yyyyyyy@yahoo.com";
        username = "yyyyyyyy";
        password = "**********";

        emailSettings();
        createSession();
        sendMessage("yyyyyyyyy@yahoo.com", "wwwwwww@wwwwww.com","Test","test Mail");
    }

    public void emailSettings() {
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.auth", "true");
        props.put("mail.debug", "false");
        props.put("mail.smtp.port", port);
        //props.put("mail.smtp.socketFactory.port", port);
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.socketFactory.fallback", "false");

    }

    public void createSession() {

        l_session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, password);
                    }
                });

        l_session.setDebug(true); // Enable the debug mode

    }

    public boolean sendMessage(String emailFromUser, String toEmail, String subject, String msg) {

        try {
            MimeMessage message = new MimeMessage(l_session);
            emailid = emailFromUser;

            message.setFrom(new InternetAddress(this.emailid));

            message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail));

            message.setSubject(subject);
            message.setContent(msg, "text/html");

            Transport.send(message);
        } catch (MessagingException mex) {
            mex.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }//end catch block
        return true;
    }


    public static void main(String args[]){
        new YahooSendMail().BSendMail();
    }

}

响应

DEBUG: setDebug: JavaMail version 1.4.1ea-SNAPSHOT
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.mail.yahoo.com", port 465, isSSL false
220 smtp.mail.yahoo.com ESMTP ready
DEBUG SMTP: connected to host "smtp.mail.yahoo.com", port: 465

   EHLO System23
   250-smtp.mail.yahoo.com
250-PIPELINING
250-SIZE 41697280
250-8 BITMIME
250 AUTH PLAIN LOGIN XYMCOOKIE
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "8", arg "BITMIME"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN XYMCOOKIE"
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
ZTJpbmZvY2F0aWUy
334 UGFzc3dvcmQ6
RTJpbmZvc3lzdGVtcw==
235 2.0.0 OK
DEBUG SMTP: use8bit false
MAIL FROM:<e2infocatie2@yahoo.com>
250 OK , completed
RCPT TO:<sivisha.s@e2infosystems.com>
250 OK , completed
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   sivisha.s@e2infosystems.com
DATA
354 Start Mail. End with CRLF.CRLF
From: e2infocatie2@yahoo.com
To: sivisha.s@e2infosystems.com
Message-ID: <1579321858.0.1382442478363.JavaMail.Administrator@System23>
Subject: Test
MIME-Version: 1.0
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

test Mail
.
**554 Transaction failed :  Cannot send message due to possible abuse; please visit http://postmaster.yahoo.com/abuse_smtp.html for more information
DEBUG SMTP: got response code 554, with response: 554 Transaction failed :  Cannot send message due to possible abuse; please visit http://postmaster.yahoo.com/abuse_smtp.html for more information**

RSET
DEBUG SMTP: EOF: [EOF]
javax.mail.MessagingException: [EOF]
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
    at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1321)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:637)
    at javax.mail.Transport.send0(Transport.java:189)
    at javax.mail.Transport.send(Transport.java:118)
    at YahooSendMail.sendMessage(YahooSendMail.java:69)
    at YahooSendMail.BSendMail(YahooSendMail.java:26)
    at YahooSendMail.main(YahooSendMail.java:81)
QUIT
javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
    java.net.SocketException: Connection closed by remote host
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1564)
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1551)
    at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:696)
    at javax.mail.Transport.send0(Transport.java:191)
    at javax.mail.Transport.send(Transport.java:118)
    at YahooSendMail.sendMessage(YahooSendMail.java:69)
    at YahooSendMail.BSendMail(YahooSendMail.java:26)
    at YahooSendMail.main(YahooSendMail.java:81)
Caused by: java.net.SocketException: Connection closed by remote host
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.checkWrite(Unknown Source)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write(Unknown Source)
    at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:114)
    at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
    at java.io.BufferedOutputStream.flush(Unknown Source)
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1562)
    ... 7 more

0 个答案:

没有答案