package mailapplet;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class receiveMailApplet extends Applet {
private boolean isStandalone = false;
private Label label1 = new Label();
private TextField textField1 = new TextField();
private Label label2 = new Label();
private TextField textField2 = new TextField();
private Label label3 = new Label();
private TextField textField3 = new TextField();
private TextArea textArea1 = new TextArea();
private Button button1 = new Button();
private Button button2 = new Button();
public static String MAIL_STORE = "pop3";
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public receiveMailApplet() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
label1.setText("邮件服务器地址");
label1.setBounds(new Rectangle(54, 25, 94, 27));
this.setLayout(null);
textField1.setBounds(new Rectangle(151, 25, 174, 28));
label2.setText("用户名");
label2.setBounds(new Rectangle(53, 61, 43, 26));
textField2.setBounds(new Rectangle(151, 63, 174, 29));
label3.setText("密码");
label3.setBounds(new Rectangle(52, 102, 33, 25));
textField3.setEchoChar('*');
textField3.setBounds(new Rectangle(151, 101, 175, 29));
textArea1.setEditable(false);
textArea1.setBounds(new Rectangle(13, 184, 551, 365));
button1.setLabel("登录");
button1.setBounds(new Rectangle(143, 142, 77, 28));
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
button1_actionPerformed(e);
}
});
button2.setLabel("重写");
button2.setBounds(new Rectangle(237, 142, 77, 28));
button2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
button2_actionPerformed(e);
}
});
this.add(label1, null);
this.add(textField1, null);
this.add(label2, null);
this.add(textField2, null);
this.add(label3, null);
this.add(textField3, null);
this.add(textArea1, null);
this.add(button1, null);
this.add(button2, null);
}
//Start the applet
public void start() {
}
//Stop the applet
public void stop() {
}
//Destroy the applet
public void destroy() {
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
//Main method
public static void main(String[] args) {
receiveMailApplet applet = new receiveMailApplet();
applet.isStandalone = true;
Frame frame;
frame = new Frame() {
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public synchronized void setTitle(String title) {
super.setTitle(title);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
}
};
frame.setTitle("Applet Frame");
frame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(500,620);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
void button2_actionPerformed(ActionEvent e) {
textField1.setText("");
textField2.setText("");
textField3.setText("");
}
void button1_actionPerformed(ActionEvent e) {
String mail_host = textField1.getText();
String user = textField2.getText();
String pass = textField3.getText();
if ((user==null)||(user.trim().length()==0))
{
JOptionPane msg = new JOptionPane();
JOptionPane.showMessageDialog(this, "用户名不能为空!", "用户名不能为空!", 0);
}
else if ((pass==null)||(pass.trim().length()==0))
{
JOptionPane msg = new JOptionPane();
JOptionPane.showMessageDialog(this, "密码不能为空!", "密码不能为空!", 0);
}
else
{
try
{
Properties props = new Properties();
props.put("mail.host", mail_host);
props.put("mail.transport.protocol", "pop3");
Session receiveMailSession;
boolean sessionDebug = false;
receiveMailSession = Session.getDefaultInstance(props, null);
receiveMailSession.setDebug(sessionDebug);
URLName url = new URLName(MAIL_STORE, mail_host, -1, "INBOX", user, pass);
Store store = receiveMailSession.getStore(url);
store.connect();
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
int n = inbox.getMessageCount();
Message[] msg = inbox.getMessages();
for(int i=0;i<n;i++)
{
textArea1.append("Letter " + String.valueOf(i+1) + "\n");
textArea1.append("Date: " + msg[i].getSentDate() + "\n");
Address a[] = msg[i].getFrom();
textArea1.append("From: " + a[0] + "\n");
a = msg[i].getRecipients(Message.RecipientType.TO);
textArea1.append("To: " + a[0] + "\n");
String s = msg[i].getSubject();
textArea1.append("Subject: " + s + "\n");
Object o = msg[i].getContent();
if (msg[i].isMimeType("text/plain"))
{
textArea1.append(o + "\n");
}
else if (msg[i].isMimeType("multipart/*"))
{
Multipart mp = (Multipart)o;
for(int j=0;j<mp.getCount();j++)
{
Part part = mp.getBodyPart(j);
String contentType = part.getContentType();
if (contentType==null)
{
textArea1.append("Bad content type for part " + String.valueOf(j) + "\n");
continue;
}
ContentType ct = new ContentType(contentType);
if (j!=0)
{
textArea1.append("\n");
}
if (ct.match("text/plain"))
{
textArea1.append(part.getContent() + "\n");
}
else
{
String desc = "Attachment ";
s = part.getFileName();
if(s!=null)
{
desc+= s;
}
textArea1.append(desc + "\n");
}
}
}
}
}
catch(Exception e1)
{
//out.println("Unable to connect to MailServer");
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
构建邮件服务器E-mail发送、发送附件、身份验证、跨代理、收取E-mail口令验证等功能.rar
共38个文件
class:17个
java:10个
jpx:7个
4星 · 超过85%的资源 需积分: 9 13 下载量 19 浏览量
2011-03-09
20:03:01
上传
评论
收藏 74KB RAR 举报
温馨提示
构建邮件服务器E-mail发送、发送附件、身份验证、跨代理、收取E-mail口令验证等功能.rar
资源推荐
资源详情
资源评论
收起资源包目录
构建邮件服务器E-mail发送、发送附件、身份验证、跨代理、收取E-mail口令验证等功能.rar (38个子文件)
javaMail编程实例
sendmail_attach
src
sendmail_attach
Email2.java 3KB
classes
sendmail_attach
Email2.class 3KB
sendmail_attach.jpx 3KB
sendmail_proxy
sendmail_proxy.jpx 3KB
src
sendmail_proxy
Email4.java 2KB
classes
sendmail_proxy
Email4.class 3KB
receivemail
receivemail.jpx 3KB
src
receivemail
Receive.java 3KB
classes
receivemail
Receive.class 4KB
sendmail
sendmail.jpx 3KB
src
JavaMail 1_2 API documentation Class MimeMessage.htm 171KB
sendmail
Email1.java 2KB
classes
sendmail
Email1.class 2KB
sendmail_authentic
sendmail_authentic.jpx 3KB
src
sendmail_authentic
Email_Autherticatorbean.java 1KB
Email3.java 3KB
classes
sendmail_authentic
Email_Autherticatorbean.class 1KB
Email3.class 3KB
mailApplet
src
mailapplet
receiveMailApplet.java 7KB
sendMailApplet.java 6KB
classes
mailapplet
receiveMailApplet.class 8KB
sendMailApplet$3.class 860B
sendMailApplet$1.class 717B
sendMailApplet$2.class 717B
receiveMailApplet$2.class 735B
receiveMailApplet$1.class 735B
sendMailApplet.class 7KB
receiveMailApplet$3.class 869B
receiveMailApplet.html 450B
receiveMailApplet.html~1~ 450B
Thumbs.db 16KB
mailApplet.jpx 3KB
receivemail_authentic
receivemail_authentic.jpx 3KB
src
receivemail_authentic
MailAuthenticator.java 2KB
Receive.java 3KB
classes
receivemail_authentic
MailAuthenticator$HideDialog.class 913B
MailAuthenticator.class 3KB
Receive.class 4KB
共 38 条
- 1
资源评论
- 托合提风飞沙2013-04-12不错,挺好用的。
- 海贼王大妈2012-12-05Java的,不知道怎么使用
- iuqazwsx2013-01-30很好 在实验的时候用到了
有庙无僧风扫地
- 粉丝: 4
- 资源: 59
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功