SMTP 客户端通过 HELO 命令停止
我一直在尝试让这个 SMTP 客户端启动并运行。客户端到达服务器并能够发送 HELO 消息。我也能够获得成功的确认。但在第一个命令之后,所有其他命令都会得到确认,表示该命令未被识别。这非常奇怪,我无法继续我的程序。请帮忙..:(
这是我的程序..你可以在 Eclipse 和 swing UI l 中编译它
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);
}
}
I have been trying to get this SMTP client up and running. The client reaches the server and is able to send the HELO message. I am also able to get a successful acknowledgement too. But after this first command all the other commands get an acknowledgement saying the command is not recogonised. This is pretty wierd and I am not able to proceed with my program. Please help..:(
Well this is my program..you can just compile it in eclipse and the swing UI l comeup
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您发送的是
HELO
而不是EHLO
,因此服务器可能未启用对 ESMTP 命令AUTH
的支持。Since you are sending
HELO
instead ofEHLO
, the server probably isn't enabling support for the ESMTP commandAUTH
.SMTP 的 RFC 5321 要求 HELO 应包含 FQDN(带有域的主机名) ,根据您使用的 SMTP 服务器,它可能会因此拒绝通信。此外,HELO 已被弃用,取而代之的是 EHLO 命令。
您是否考虑过使用 Java Mail 或 Commons-email 而不是自己处理所有协议?
The RFC 5321 for SMTP requires that HELO should include a FQDN (a hostname with domain), depending on which SMTP Server you are using it might refuse communication because of that. Furthermore HELO is deprecated in favour of EHLO command.
Did you consider using Java Mail or Commons-email instead of doing all the protocol handling yourself?