gpt4 book ai didi

java - SMTP 客户端使用 HELO 命令停止

转载 作者:行者123 更新时间:2023-12-02 08:08:02 25 4
gpt4 key购买 nike

我一直在尝试让这个 SMTP 客户端启动并运行。客户端到达服务器并能够发送 HELO 消息。我也能够获得成功的确认。但在第一个命令之后,所有其他命令都会得到确认,表示该命令未被识别。这非常奇怪,我无法继续我的程序。请帮忙..:(

这是我的程序..你可以在 Eclipse 和 swing UI 中编译它

enter code here   
import java.awt.*;
import java.io.*;
import java.net.Socket;

import javax.swing.*;



public class Mail extends javax.swing.JFrame {



JLabel userLabel = new JLabel("USER");
JLabel passLabel = new JLabel("PASS");
JLabel fromLabel = new JLabel("FROM");
JLabel toLabel = new JLabel("TO");
JLabel subjectLabel = new JLabel("SUBJECT");
JLabel bodyLabel = new JLabel("BODY");
JLabel serverLabel=new JLabel("SERVER");
JButton sendButton = new JButton("Send");
JButton closeButton = new JButton("Close");
JTextField userText= new JTextField();
JPasswordField passText= new JPasswordField();
JTextField fromText= new JTextField();
JTextField toText= new JTextField();
JTextField subjectText= new JTextField();
JTextField bodyText = new JTextField();
JTextField serverText = new JTextField("smtp.nus.edu.sg");
JList testList= new JList() ;
JTextArea test= new JTextArea() ;
DefaultListModel testArea= new DefaultListModel();
BufferedReader input ;
PrintWriter output ;


public Mail(){

setTitle("User Agent");
this.setSize(1400,1400);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(null);





userLabel.setBounds(12, 12, 70, 12);
passLabel.setBounds(12, 48, 70, 12);
fromLabel.setBounds(12, 84, 70, 12);
toLabel.setBounds(12, 120, 70, 12);
subjectLabel.setBounds(12, 156, 70, 12);
bodyLabel.setBounds(12, 192, 70, 12);
serverLabel.setBounds(12, 228, 70, 12);
sendButton.setBounds(12, 264, 70, 22);
closeButton.setBounds(130, 264, 70, 22);
//testArea.setBounds(130, 294, 170, 122);

userText.setBounds(60,12,200,22);
passText.setBounds(60,48,200,22);
fromText.setBounds(60,84,200,22);
toText.setBounds(60,120,200,22);
subjectText.setBounds(60,156,200,22);
bodyText.setBounds(60,192,200,22);
serverText.setBounds(60,228,200,22);
testList.setBounds(130, 294, 970, 922);
test.setBounds(400, 294, 970, 922);


getContentPane().add(userLabel);
getContentPane().add(passLabel);
getContentPane().add(fromLabel);
getContentPane().add(toLabel);
getContentPane().add(subjectLabel);
getContentPane().add(bodyLabel);
getContentPane().add(serverLabel);
getContentPane().add(sendButton);
getContentPane().add(closeButton);
getContentPane().add(userText);
getContentPane().add(passText);
getContentPane().add(fromText);
getContentPane().add(toText);
getContentPane().add(subjectText);
getContentPane().add(bodyText);
getContentPane().add(serverText);
getContentPane().add(testList);
// getContentPane().add(test);

testList.setModel(testArea);
testArea.addElement("this is a test message");

/*thehandler handler = new thehandler();
sendButton.addActionListener(handler);
*/
theHandler handler = new theHandler();
closeButton.addActionListener(handler);
sendButton.addActionListener(handler);
}
class theHandler implements java.awt.event.ActionListener{

public void actionPerformed(java.awt.event.ActionEvent event){
Object happen = event.getSource();
if (happen == closeButton)
closeButton_actionPerformed(event);
else if(happen == sendButton)
sendButton_actionPerformed(event);


}
}

/*void Send_actionPerformed(java.awt.event.ActionEvent event) {
System.exit(0);
}*/



void closeButton_actionPerformed(java.awt.event.ActionEvent event) {
System.exit(0);
//testText.setText("vikas");
}

void sendButton_actionPerformed(java.awt.event.ActionEvent event) {

try{
Socket sock = new Socket(serverText.getText(), 25);
//testArea.addElement(sock);
output = new PrintWriter(sock.getOutputStream(),true);
input = new BufferedReader(new InputStreamReader(sock.getInputStream()));




//output.flush();

pass(null);
pass("HELO\r\n");
pass("AUTH LOGIN\r\n");
//pass("AUTH LOGIN\r\n");
//pass(null);



//pass("TlVTU1RVXHUwOTA2OTc1");
//pass("TlVTU1RVXHUwOTA2OTc1");


}
catch(Exception e){
testArea.addElement("Error");
}
}
//testText.setText("vikas");


void pass(String s)throws java.io.IOException{

if(s!=null){
output.println(s);
System.out.println(s);


testArea.addElement("Me");
testArea.addElement(s);
}




String inline = input.readLine();
if(inline!= null)
testArea.addElement("Him");
testArea.addElement(inline);

// test.setText(inline);

}

public static void main(String args[]) {
Mail theMail = new Mail();
theMail.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


}



}

最佳答案

由于您发送的是 HELO 而不是 EHLO,服务器可能未启用对 ESMTP 命令 AUTH 的支持。

关于java - SMTP 客户端使用 HELO 命令停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7861069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com