我正在用jbulider做一个电子邮件客户程序,给点建议!100分! Java Mail。看一下Wrox的Java网络编程指南,其中有一章专门讲Java Mail 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参看一下下边这个例子吧。http://expert.csdn.net/Expert/topic/1177/1177970.xml?temp=.7992823 问一下,wrox的java网络编程指南哪里有?谢了! import java.awt.*;import java.awt.event.*;import java.util.*;import java.net.*;import java.io.*;import javax.swing.*;public class MailTest{ public static void main(String[] args) { JFrame frame = new MailTestFrame(); frame.show(); }}class MailTestFrame extends JFrame implements ActionListener{ public MailTestFrame() { setTitle("MailTest"); setSize(300, 300); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 0; gbc.weighty = 0; gbc.weightx = 0; add(new JLabel("From:"), gbc, 0, 0, 1, 1); gbc.weightx = 100; from = new JTextField(20); add(from, gbc, 1, 0, 1, 1); gbc.weightx = 0; add(new JLabel("To:"), gbc, 0, 1, 1, 1); gbc.weightx = 100; to = new JTextField(20); add(to, gbc, 1, 1, 1, 1); gbc.weightx = 0; add(new JLabel("SMTP server:"), gbc, 0, 2, 1, 1); gbc.weightx = 100; smtpServer = new JTextField(20); add(smtpServer, gbc, 1, 2, 1, 1); gbc.fill = GridBagConstraints.BOTH; gbc.weighty = 100; message = new JTextArea(); add(new JScrollPane(message), gbc, 0, 3, 2, 1); response = new JTextArea(); add(new JScrollPane(response), gbc, 0, 4, 2, 1); gbc.weighty = 0; JButton sendButton = new JButton("Send"); sendButton.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.add(sendButton); add(buttonPanel, gbc, 0, 5, 2, 1); } private void add(Component c, GridBagConstraints gbc, int x, int y, int w, int h) { gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; getContentPane().add(c, gbc); } public void actionPerformed(ActionEvent evt) { SwingUtilities.invokeLater(new Runnable() { public void run() { sendMail(); } }); } public void sendMail() { try { Socket s = new Socket(smtpServer.getText(), 25); out = new PrintWriter(s.getOutputStream()); in = new BufferedReader(new InputStreamReader(s.getInputStream())); String hostName = InetAddress.getLocalHost().getHostName(); send(null); send("HELO " + hostName); send("MAIL FROM: " + from.getText()); send("RCPT TO: " + to.getText()); send("DATA"); out.println(message.getText()); send("."); s.close(); } catch (IOException exception) { response.append("Error: " + exception); } } public void send(String s) throws IOException { if (s != null) { response.append(s + "\n"); out.println(s); out.flush(); } String line; if ((line = in.readLine()) != null) response.append(line + "\n"); } private BufferedReader in; private PrintWriter out; private JTextField from; private JTextField to; private JTextField smtpServer; private JTextArea message; private JTextArea response;}这是java core的一个例子,我在hotmail作实验,每次都说连接超时,请问为何? 文件或文件夹复制 线程 中断问题 求大神解析 JTextArea的换行问题 BULK INSERT 怎么设置SWT中Dialog窗口标题 页面有个播放器,播放歌曲,然后根据播放的歌曲,生成一个选择题,让选择现在播放的歌曲的名字,怎么来实现? Java实现多线程服务器时出现的疑难问题 急!请大家看看这个问题,100分不够可以加! 运行出错 java POI 写 EXCEL文件的问题 关于java生成的exe文件不能运行的问题 如何将.zip文件改为.jar文件?
http://expert.csdn.net/Expert/topic/1177/1177970.xml?temp=.7992823
谢了!
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;public class MailTest
{ public static void main(String[] args)
{ JFrame frame = new MailTestFrame();
frame.show();
}
}class MailTestFrame extends JFrame
implements ActionListener
{ public MailTestFrame()
{ setTitle("MailTest");
setSize(300, 300);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} ); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0;
gbc.weighty = 0; gbc.weightx = 0;
add(new JLabel("From:"), gbc, 0, 0, 1, 1);
gbc.weightx = 100;
from = new JTextField(20);
add(from, gbc, 1, 0, 1, 1); gbc.weightx = 0;
add(new JLabel("To:"), gbc, 0, 1, 1, 1);
gbc.weightx = 100;
to = new JTextField(20);
add(to, gbc, 1, 1, 1, 1); gbc.weightx = 0;
add(new JLabel("SMTP server:"), gbc, 0, 2, 1, 1);
gbc.weightx = 100;
smtpServer = new JTextField(20);
add(smtpServer, gbc, 1, 2, 1, 1); gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 100;
message = new JTextArea();
add(new JScrollPane(message), gbc, 0, 3, 2, 1); response = new JTextArea();
add(new JScrollPane(response), gbc, 0, 4, 2, 1); gbc.weighty = 0;
JButton sendButton = new JButton("Send");
sendButton.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.add(sendButton);
add(buttonPanel, gbc, 0, 5, 2, 1);
} private void add(Component c, GridBagConstraints gbc,
int x, int y, int w, int h)
{ gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
getContentPane().add(c, gbc);
} public void actionPerformed(ActionEvent evt)
{ SwingUtilities.invokeLater(new Runnable()
{ public void run()
{ sendMail();
}
});
} public void sendMail()
{ try
{ Socket s = new Socket(smtpServer.getText(), 25); out = new PrintWriter(s.getOutputStream());
in = new BufferedReader(new
InputStreamReader(s.getInputStream())); String hostName
= InetAddress.getLocalHost().getHostName(); send(null);
send("HELO " + hostName);
send("MAIL FROM: " + from.getText());
send("RCPT TO: " + to.getText());
send("DATA");
out.println(message.getText());
send(".");
s.close();
}
catch (IOException exception)
{ response.append("Error: " + exception);
}
} public void send(String s) throws IOException
{ if (s != null)
{ response.append(s + "\n");
out.println(s);
out.flush();
}
String line;
if ((line = in.readLine()) != null)
response.append(line + "\n");
} private BufferedReader in;
private PrintWriter out;
private JTextField from;
private JTextField to;
private JTextField smtpServer;
private JTextArea message;
private JTextArea response;
}
这是java core的一个例子,我在hotmail作实验,每次都说连接超时,请问为何?