java mail 接收,使用javamail API接收邮件

i am using javamail api to configure a receiver but its throwing an exception. i don't know how to resolve it. i am just a beginner to javamail. i am actaully not getting what exactly it wants me to do. please anybody give me the proper solution.

my code is:

package com.message;

import javax.mail.*;

import java.util.*;

import java.io.*;

public class Receiver

{

public static void main(String[] args)

{

Properties props = new Properties();

String host = "pop3.gmail.com";

String username = "emailid";

String password = "pasword";

String provider = "pop3";

try

{

// Connect to the POP3 server

Session session = Session.getInstance(props);

Store store = session.getStore(provider);

store.connect(host,username, password);

// Open the folder

Folder inbox = store.getFolder("INBOX");

if (inbox == null)

{

System.out.println("No INBOX");

System.exit(1);

}

inbox.open(Folder.READ_ONLY);

// Get the messages from the server

Message[] messages = inbox.getMessages();

for (int i = 0; i < messages.length; i++)

{

System.out.println("Message"+(i+1));

messages[i].writeTo(System.out);

}

// Close the connection

// but don't remove the messages from the server

inbox.close(false);

store.close();

}

catch (MessagingException ex)

{

ex.printStackTrace();

}

catch(IOException ex)

{

ex.printStackTrace();

}

}

}

and the exception is:

javax.mail.MessagingException: Connect failed;

nested exception is:

java.net.UnknownHostException: pop3.gmail.com

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:160)

at javax.mail.Service.connect(Service.java:291)

at javax.mail.Service.connect(Service.java:172)

at com.message.Receiver.main(Receiver.java:20)

Caused by: java.net.UnknownHostException: pop3.gmail.com

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:367)

at java.net.Socket.connect(Socket.java:524)

at java.net.Socket.connect(Socket.java:474)

at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:267)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)

at com.sun.mail.pop3.Protocol.(Protocol.java:91)

at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:213)

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:156)

... 3 more

anybody please solve this problem.

解决方案

Try pop.gmail.com that is apparently the right address.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值