我想跟其他语言没有什么两样,创建socket 通过110 port取信.
用telnet就是:
telnet pop3.sina.com 110
USER XXX
PASS XXXXXX
LIST
用socket发送每一次上面的指令,然后看接受mail server的返回信息返回信息一般有'OK'就代表成功了.
LIST能列出有多少信.具体pop3协议请参照(RFC1939)
但你接了信,附件你只能得到是编过码(base64,printable...)的正文,你要根据头来采取一种解码.具体编码方式每种都不一样,看了邮件你就知道了.
用telnet就是:
telnet pop3.sina.com 110
USER XXX
PASS XXXXXX
LIST
用socket发送每一次上面的指令,然后看接受mail server的返回信息返回信息一般有'OK'就代表成功了.
LIST能列出有多少信.具体pop3协议请参照(RFC1939)
但你接了信,附件你只能得到是编过码(base64,printable...)的正文,你要根据头来采取一种解码.具体编码方式每种都不一样,看了邮件你就知道了.
解决方案 »
- Smack文件传输的问题
- 大神,求教xml反编译txt的问题
- 我在一个jdialog1中打开了另一个jdialog2,想实现单击jdialog2中的某个按钮可以刷新jdialog1中的表格。怎么实现呢
- java applet 和使用的WEB 服务器有关?(急!在线等!)
- 字符串的替换问题
- 请教下JAVA实现手机短信收发问题
- jdbc连接SQL SERVER数据库在IE中显示(socket方面的)出错,请求帮助!
- 加了滚动条textArea不能用了,怎么改?
- 为什么没人来(laocai8),真失望,雷锋哪去了?????????
- 又一个入门级的问题:关于在Graphics中输出文字
- 怎样将一个GMT日期格式转换成CST时间?
- 关于NetBeans的问题:有没有介绍NetBeans的中文资料
in = new BufferedReader(new InputStreamReader (sock.getInputStream(),"8859_1"));
out = new DataOutputStream(sock.getOutputStream()); result = in.readLine();
System.out.println(result); out.writeBytes("HELO "+ "bootcool"+"\n");
System.out.println("HELO "+ InetAddress.getLocalHost ().getHostAddress()+"\n"); result = in.readLine();
System.out.println(result);
System.out.println("**********");out.writeBytes("USER "+ "********"+"\n");
result = in.readLine();
System.out.println(result); out.writeBytes("PASS "+ "*********"+"\n");
result = in.readLine();
System.out.println(result); out.writeBytes("STAT "+"\n"); out.writeBytes("UIDL "+"\n");
result = in.readLine();
System.out.println(result);out.writeBytes("LIST "+"\n");
result = in.readLine();
System.out.println(result);
out.writeBytes("RETR 1");
result = in.readLine();
System.out.println(result);可是这里的输出却是null不知如何才能得到正文的内容呢?
你发出的USER ,PASS 指令确定成功了吗?
如果成功pop3 server返回的信息如pop3.sina.com.cn 是+OK,你就可以判断有没有这个字串,有就是成功了.
再试一试.
HELO 202.96.44.43+OK POP3 Example Server Ready
**********
+OK core mail
+OK 5 message(s) [2543 byte(s)]
+OK 5 2543
+OK 5 2543
QUIT但是如何才能在客户端得到邮件的正文内容呢?
就像foxmail那样.
你应该能取得类似以下内容
这是一封csdn发给我的信.Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: (qmail 82745 invoked from network); 7 Feb 2001 02:50:05
Received: from unknown (HELO midatech.com) (211.100.8.152)
by 202.106.187.186 with SMTP; 7 Feb 2001 02:50:05 -0000
Received: from csdnmail [211.101.228.181] by midatech.com
(SMTPD32-5.01 EVAL) id A61F7630260; Wed, 07 Feb 2001 10:38:23 PS
From: CSDN专家门诊<[email protected]>
To: [email protected]
Subject: 关于:跟ejb有关的问题
Reply-To: 此信不能回,请到论坛发言
Mime-Version: 1.0
Content-Type: text/plain; charset=gb2312
Message-Id: <200102071038.SM00158@csdnmail>
Date: Wed, 7 Feb 2001 10:38:24 PST
cming,您好:
关于:跟ejb有关的问题
robber提供了如下回答, 请您查阅和评估:
----------------------------------------------------由container来完成可能更易于控制吧!----------------------------------------------------
如果这个回复已经解决了您的问题,请到论坛给分给回答您问题的用户。
问题:http://www.csdn.net/expert/TopicView.asp?id=65774
中国软件开发网络: http://www.csdn.net/
中国软件开发网络专家门诊: http://expert.csdn.net/
.看到最后的.没有?这就是正文结束的标志.这是没有附件的,有附件的就麻烦了,得自己解码了,最常见的是base64,你自己写段base64解码的java代码.
取附件与内容,有分割标志如新浪的是:
boundary="----------97401812817428SINAEMAIL---"
你的pop3 server也有,自己好好看看.
这是我的原码.
import java.io.*;
import java.net.*;
import java.util.*;public class mypop3 { public static void main(String[] args) throws IOException, UnknownHostException
{ String mailHost;
mailHost = "263.net";
POP3Connection mail = new POP3Connection(mailHost);
mail.Receive();
}
} class POP3Connection
{
final static int PORT = 110;
static InetAddress r_ip; public POP3Connection(String host) throws UnknownHostException
{
r_ip = InetAddress.getByName(host);
} public boolean Receive() throws IOException
{
// Create Socket
BufferedReader in, msg;
DataOutputStream out;
Socket sock;
String result, line,pass,name; if ((sock = new Socket(r_ip, PORT)) == null)
return false; in = new BufferedReader(new InputStreamReader (sock.getInputStream(),"8859_1"));
out = new DataOutputStream(sock.getOutputStream());
result = in.readLine();
System.out.println(result);
out.writeBytes("HELO "+ "bootcool"+"\n");
System.out.println("HELO "+ r_ip.getHostAddress()+"\n");
result = in.readLine();
System.out.println(result);
out.writeBytes("USER "+ "bootcool"+"\n");
result = in.readLine();
System.out.println(result);
out.writeBytes("PASS "+ "********"+"\n");
result = in.readLine();
System.out.println(result);
out.writeBytes("STAT "+"\n");
out.writeBytes("LIST "+"\n");
result = in.readLine();
System.out.println(result); out.writeBytes("RETR 1");
result = in.readLine();
System.out.println(result);
out.writeBytes("UIDL 1 "+"\n");
result = in.readLine();
System.out.println(result);
//out.writeBytes("TOP 1"+"\n");
//result = in.readLine();
//System.out.println(result);
//out.writeBytes("DELE 1"+"\n");
//result = in.readLine();
//System.out.println(result);
out.writeBytes("QUIT"+"\n");
System.out.println("QUIT");
result = in.readLine();
System.out.println(result);
sock.close(); return true;
}
}
不知错在哪了?
请指教.
求求了
我会加分的.
循环条件是
判断 "/n" + "." + "/n" 这个字串出现了没有,
if 有
收完
退出
else
继续收
out.writeBytes("LIST 1"+"\n");
result = in.readLine();
System.out.println(result); out.writeBytes("RETR 1");
for( result = in.readLine(); result!= "/n" + "." + "/n" ; result = in.readLine())
{ System.out.println(result);
}
out.writeBytes("UIDL 1 "+"\n");
result = in.readLine();
System.out.println(result);
可是好像还是不行.
你说得很对.
可是可是System.out.println(result);
却看不到内容.
我想就是
for( result = in.readLine(); result!= "\n" + "." + "\n" ; result = in.readLine())
{ System.out.println(result);
}
这有不对的地方.
结果总是
null
null
null
null
......
不能用=;但是我看了一下java函数
好像没有包含
不过我想是不是能用indexOf(),HE和subString()两个结合着用呢?
请指教呀.
太谢谢了.
endString = "\n" + "." + "\n";
while(result.indexOf(endString) == -1)
{
result + = in.readLine();
//System.out.println(result);
}
System.out.println(result);
out.writeBytes("RETR 1"+"\n");
String endString = "\n" + "." + "\n";
while(result.indexOf(endString) == -1)
{
result = in.readLine();
System.out.println(result);
}
不用result + = in.readLine();
谢谢.还请今后多多指教呀!