我用
smtp.263.net能发送邮件
用
pop3.263.net接收文件就出现如下错误:
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.UnknownHostException: pop3.263.net
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:106)
at javax.mail.Service.connect(Service.java:234)
at javax.mail.Service.connect(Service.java:135)
at MailIncept.receive(MailIncept.java:54)
at MailIncept.main(MailIncept.java:29)
Press any key to continue...请问263接收邮件的服务器怎么写?
smtp.263.net能发送邮件
用
pop3.263.net接收文件就出现如下错误:
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.UnknownHostException: pop3.263.net
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:106)
at javax.mail.Service.connect(Service.java:234)
at javax.mail.Service.connect(Service.java:135)
at MailIncept.receive(MailIncept.java:54)
at MailIncept.main(MailIncept.java:29)
Press any key to continue...请问263接收邮件的服务器怎么写?
package testmail;import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Date;
import javax.activation.*;
import java.io.*;
import javax.swing.*;
import java.util.*;public class receiveMail {
private Properties props; //声明属性
private Session session; //声明Session
private Store store;
private Folder folder;
private String host = "mail.courage.com.cn";
private String username = "ltf";
private String password = "111111"; public static String getISOFileName(Part body) {
//设置一个标志,判断文件名从Content-Disposition中获取还是从Content-Type中获取
boolean flag = true;
if (body == null) {
return null;
}
String[] cdis;
try {
cdis = body.getHeader("Content-Disposition");
}
catch (Exception e) {
return null;
} if (cdis == null) {
flag = false;
} if (!flag) {
try {
cdis = body.getHeader("Content-Type");
}
catch (Exception e) {
return null;
}
}
if (cdis == null) {
return null;
} if (cdis[0] == null) {
return null;
}
//从Content-Disposition中获取文件名
if (flag) {
int pos = cdis[0].indexOf("filename=");
if (pos < 0) {
return null;
}
//如果文件名带引号
if (cdis[0].charAt(cdis[0].length() - 1) == '"') {
return cdis[0].substring(pos + 10, cdis[0].length() - 1);
}
return cdis[0].substring(pos + 9, cdis[0].length());
}
else {
int pos = cdis[0].indexOf("name=");
if (pos < 0) {
return null;
}
//如果文件名带引号
if (cdis[0].charAt(cdis[0].length() - 1) == '"') {
return cdis[0].substring(pos + 6, cdis[0].length() - 1);
}
return cdis[0].substring(pos + 5, cdis[0].length());
}
} public static void getPart(Part p) throws Exception {
FileOutputStream F;
InputStream is = p.getInputStream();
String s = "";
String f = ""; if (! (is instanceof BufferedInputStream)) {
is = new BufferedInputStream(is); }
String disp = p.getDisposition();
f = p.getContent().toString();//得到各部分的内容 if (disp != null && (disp.equalsIgnoreCase(p.ATTACHMENT))) {
try{
s = p.getFileName();
//s = new String(getISOFileName(p).getBytes("ISO-8859-1"),"gb2312");
F = new FileOutputStream("C:\\" + s); }catch (Exception e) {
s = MimeUtility.decodeText(getISOFileName(p));
F = new FileOutputStream("C:\\" + s);
}
s = s + "";
//F = new FileOutputStream("C:\\" + s);
int c;
while ( (c = is.read()) != -1) {
F.write(c);
}
F.close(); }
} public static void dumpPart(Part p) throws Exception {
InputStream is = p.getInputStream();
String s = "";
if (! (is instanceof BufferedInputStream)) {
is = new BufferedInputStream(is);
}
/* String disp = p.getDisposition();
if (disp != null && (disp.equalsIgnoreCase(p.ATTACHMENT))) {
s = p.getFileName();
FileOutputStream F = new FileOutputStream("C:\\" + s);
int c;
while ( (c = is.read()) != -1) {
F.write(c);
}
F.close();
}
*/
if (p.isMimeType("multipart/*")) { Multipart mp = (Multipart) p.getContent();
int count = mp.getCount();
for (int i = 0; i < count; i++) {
getPart(mp.getBodyPart(i));
}
} } public receiveMail(JTextArea jta) {
String s = ""; try {
try {
props = new Properties();
session = Session.getDefaultInstance(props, null);
store = session.getStore("pop3");
store.connect(host, username, password);
folder = store.getFolder("INBOX"); //得到收件箱
folder.open(Folder.READ_ONLY); //以只读方式打开 Message message[] = folder.getMessages();
for (int i = 0; i < folder.getMessageCount(); i++) {
s = message[i].getFrom()[0].toString();
//s = ((InternetAddress)message[0].getFrom()[0]).getPersonal();
jta.append(s + "\n");
s = message[i].getSubject();
//c = c + new Integer(i).toString() + ":" + message[i].getContent();
jta.append(s + "\n"); dumpPart(message[i]);
}
//jta.append("内容:" + c); }
finally {
folder.close(false);
store.close();
}
} catch (Exception e) {
System.out.print(e.toString());
} }}
263.net 263.net smtp.263.net
x263.net pop.x263.net smtp.x263.net
263.net.cn 263.net.cn 263.net.cn