讨论JavaEmail,现在遇到了问题,请高手帮个忙!谢谢
看了很多网上的贴子,也在Baidu上搜过.
现有两个问题.
一是收邮件时.如果原文件带附件.那么正文部份ContentType,并不是以Text/html开头
而是以.multipart/Alternative.
163及126都是这样,并带有 boundary= "----=_Part_76_1173198205.1187629828559 "
请问是不是除了 自行解释用 boundary进行拆分外,别无解决办法?,附件我是收下来了.但正文部分,一直收到Null
二是发邮件.老是被拒绝..
代码如下.
package asp.email;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import asp.BaseHibernateDAO;
import asp.cmp.Employee;
import asp.dao.sys.EmailDAO;
import asp.dao.sys.EmailServerDAO;
/**
* 带口令验证的邮件接收类.
*/
public class EmailReceive extends BaseHibernateDAO {
public EmailReceive() {
}
public boolean receive(Employee emp,String path) {
EmailServerDAO emailServerDao = new EmailServerDAO();
String emailName = emp.getEmpEmail();
String emailPass = emp.getEmpEmailPassword();
String popServer = emailServerDao.getEmailServe(emailName, false);
System.out.println(popServer);
Store store = null;
Folder folder = null;
try {
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props,
new Email_autherticator(emailName, emailPass));
store = session.getStore( "pop3 ");
store.connect(popServer, null, null);
folder = store.getDefaultFolder();
if (folder == null)
throw new Exception( "No default folder ");
folder = folder.getFolder( "INBOX ");
if (folder == null)
throw new Exception( "No POP3 INBOX ");
folder.open(Folder.READ_WRITE);
Message[] msgs = folder.getMessages();
if (msgs.length > 0) {
for (int msgNum = 0; msgNum < msgs.length; msgNum++) {
printMessage(msgs[msgNum], emp, popServer, emailName, path);// 收邮件
//msgs[msgNum].setFlag(Flags.Flag.DELETED, true);// 收完后,删除邮件
}
return true;
} else {
return false;
}
} catch (Exception ex) {
ex.printStackTrace();
return false;
} finally {
try {
if (folder != null)
folder.close(true);
if (store != null)
store.close();
} catch (Exception ex2) {
ex2.printStac