1.sslsocketfactoryԴ?源码?
2.倾家荡产,请大家帮我写个java代码,please!!!
sslsocketfactoryԴ??
你那个 SSLSocketFactory(ks) 是自己的类?
你有用过 KeyManager.init (...)? 和 TrustManager.init(...) ?
想要在连接建立过程上交互式的弹出确认对话框来的话需要我们自己提供一个 KeyManager 和 TrustManager 的实现类,这有点复杂,源码wannaren源码你可以看一个 Sun 的源码社区建站系统源码 XKeyManager 是怎么做的,默认地情况下它是源码小刀代挂网源码从自动搜索匹配的 subject ,我们需要用自己提供的源码疯狂解析vip源码方式弹出确认的过程还不是全自动,另外一个账户可能有多个数字证书,源码微信飞艇源码比如支付宝我们就有多个签发时间不一样的源码数字证书,在连接建立时 IE 会提示我们选择其中的源码一个来使用,银行的源码 U 盾在安装多张数字证书时也会提示我们选择其中一个对应到你正在使用的银行卡号的那张证书。
倾家荡产,源码请大家帮我写个java代码,please!!!
package org.job.six;
import java.io.UnsupportedEncodingException;
import java.security.Security;
import java.util.Properties;
import javax.mail.FetchProfile;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;
import org.job.util.Logger;
import org.job.util.mail.ApplicationContext;
/
*** 用于收取Gmail邮件
*
* @author wuhua
*/
public class GmailFetch {
private static Logger logger = Logger.getLogger(GmailFetch.class);
public static void main(String argv[]) throws Exception {
logger.debug("开始读取邮件");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.port", "");
props.setProperty("mail.pop3.socketFactory.port", "");
// 以下步骤跟一般的JavaMail操作相同
Session session = Session.getDefaultInstance(props, null);
// 请将红色部分对应替换成你的邮箱帐号和密码
URLName urln = new URLName("pop3", ApplicationContext.POP3, , null,
ApplicationContext.GMAIL_MAIL_NAME,
ApplicationContext.GMAIL_MAIL_PASSWORD);
Store store = session.getStore(urln);
Folder inbox = null;
try {
store.connect();
inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
Message[] messages = inbox.getMessages();
inbox.fetch(messages, profile);
logger.debug("收件箱的邮件数:" + messages.length);
for (int i = 0; i < messages.length; i++) {
// 邮件发送者
String from = decodeText(messages[i].getFrom()[0].toString());
InternetAddress ia = new InternetAddress(from);
logger.debug("发信人:" + ia.getPersonal() + '('
+ ia.getAddress() + ')');
// 邮件标题
logger.debug("主题:" + messages[i].getSubject());
// 邮件大小
logger.debug("邮件大小:" + messages[i].getSize());
// 邮件发送时间
logger.debug("发送日期:" + messages[i].getSentDate());
}
} finally {
try {
inbox.close(false);
} catch (Exception e) {
}
try {
store.close();
} catch (Exception e) {
}
}
logger.debug("读取邮件完毕");
}
protected static String decodeText(String text)
throws UnsupportedEncodingException {
if (text == null)
return null;
if (text.startsWith("=?GB") || text.startsWith("=?gb"))
text = MimeUtility.decodeText(text);
else
text = new String(text.getBytes("ISO_1"));
return text;
}
}
package org.job.six;
import java.io.UnsupportedEncodingException;
import java.security.Security;
import java.util.Properties;
import javax.mail.FetchProfile;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;
import org.job.util.Logger;
import org.job.util.mail.ApplicationContext;
/
*** 用于收取Gmail邮件
*
* @author wuhua
*/
public class GmailFetch {
private static Logger logger = Logger.getLogger(GmailFetch.class);
public static void main(String argv[]) throws Exception {
logger.debug("开始读取邮件");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.port", "");
props.setProperty("mail.pop3.socketFactory.port", "");
// 以下步骤跟一般的JavaMail操作相同
Session session = Session.getDefaultInstance(props, null);
// 请将红色部分对应替换成你的邮箱帐号和密码
URLName urln = new URLName("pop3", ApplicationContext.POP3, , null,
ApplicationContext.GMAIL_MAIL_NAME,
ApplicationContext.GMAIL_MAIL_PASSWORD);
Store store = session.getStore(urln);
Folder inbox = null;
try {
store.connect();
inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
Message[] messages = inbox.getMessages();
inbox.fetch(messages, profile);
logger.debug("收件箱的邮件数:" + messages.length);
for (int i = 0; i < messages.length; i++) {
// 邮件发送者
String from = decodeText(messages[i].getFrom()[0].toString());
InternetAddress ia = new InternetAddress(from);
logger.debug("发信人:" + ia.getPersonal() + '('
+ ia.getAddress() + ')');
// 邮件标题
logger.debug("主题:" + messages[i].getSubject());
// 邮件大小
logger.debug("邮件大小:" + messages[i].getSize());
// 邮件发送时间
logger.debug("发送日期:" + messages[i].getSentDate());
}
} finally {
try {
inbox.close(false);
} catch (Exception e) {
}
try {
store.close();
} catch (Exception e) {
}
}
logger.debug("读取邮件完毕");
}
protected static String decodeText(String text)
throws UnsupportedEncodingException {
if (text == null)
return null;
if (text.startsWith("=?GB") || text.startsWith("=?gb"))
text = MimeUtility.decodeText(text);
else
text = new String(text.getBytes("ISO_1"));
return text;
}
}