2 u013749192 u013749192 于 2015.06.29 09:28 提问

Couldn't connect to host链接超时
new

/**
* PraseMimeMessage类测试
* @param args
* @throws Exception
*/
public static void main(String args[])throws Exception{
// String host="主机名/ip"; //【pop.mail.yahoo.com.cn】
// String username="用户名"; //【wwp_1124】
// String password="密码"; //【........】
String host="smtp.gmail.com"; //【pop.mail.yahoo.com.cn】
String username="刚注册的163邮箱"; //【wwp_1124】
String password="163邮箱密码";
Properties props=new Properties();
props.put("port", "110");
props.setProperty("mail.smtp.connectiontimeout", "80000");
Session session = Session.getDefaultInstance(props,null);
Store store=session.getStore("pop3");
store.connect(host,username,password);
Folder folder=store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message message[]=folder.getMessages();
System.out.println("Messages's length: "+message.length);
PraseMimeMessage pmm=null;
for(int i=0;i<message.length;i++){
pmm=new PraseMimeMessage((MimeMessage)message[i]);

        System.out.println("Message "+i+" subject: "+pmm.getSubject());
        System.out.println("Message "+i+" sentdate: "+pmm.getSentDate());
        System.out.println("Message "+i+" replysign: "+pmm.getReplySign());
        System.out.println("Message "+i+" hasRead: "+pmm.isNew());
        System.out.println("Message "+i+"  containAttachment: "+pmm.isContainAttach((Part)message[i]));
        System.out.println("Message "+i+" form: "+pmm.getFrom());
        System.out.println("Message "+i+" to: "+pmm.getMailAddress("to"));
        System.out.println("Message "+i+" cc: "+pmm.getMailAddress("cc"));
        System.out.println("Message "+i+" bcc: "+pmm.getMailAddress("bcc"));
        pmm.setDateFormat("yy年MM月dd日 HH:mm");
        System.out.println("Message "+i+" sentdate: "+pmm.getSentDate());
        System.out.println("Message "+i+" Message-ID: "+pmm.getMessageId());
        pmm.getMailContent((Part)message[i]);
        System.out.println("Message "+i+" bodycontent: \r\n"+pmm.getBodyText());
        pmm.setAttachPath("c:\\tmp\\coffeecat1124");
        pmm.saveAttachMent((Part)message[i]);
    }

3个回答

u013749192
u013749192   2015.06.29 09:29

报错信息:
Exception in thread "main" com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 110; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out: connect

u013749192
u013749192   2015.06.29 09:34

store.connect(host,username,password);这句话就链接超时了,谢谢大伙了~

nijun_2011
nijun_2011   2015.06.29 10:35

请点击下面链接,参考关于企业邮件发送组建完整的实现步骤及源码下载(分别提供maven项目及web项目源码),请参考http://www.xwood.net/_site_domain_/_root/5870/5874/t_c254966.html

u013749192
u013749192 好,我看看
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片