JavaMail->Host->Port 如何设置?

bxh777 hner IT运维总监  2002-05-26 06:25:17
加精
邮件代理服务器默认端口为25,如何更改呢?
...全文
223 点赞 收藏 5
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
realyinjr2 2002-06-19
谢谢,
大虾真慷慨,我正急需呢。
回复
hydrus 2002-06-18
// 经典代码----收邮件

<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
Properties props = new Properties();
props.put("mail.smtp.host","192.168.199.3");
Session s = Session.getInstance(props,null);

// Store store = s.getStore("pop3");

int port = 8110;
String username = "yourname#pop.21cn.com";
String password = "******";
String server = "192.168.199.1";
String protocol = "pop3";
String file = "C:/home/mail/999/Maildir/rev";


s.setDebug(false);
URLName urln = new URLName(protocol,server,port,file,username,password);
// URLName urln = new URLName(CONST.maildir,CONST.mailhost,8008,maildir,userid,passwd);
Store store = s.getStore(urln);
s.setDebug(true); // true = s.getDebug() 有何实际意义???

// URLName url = new URLName(protocol,getHostname(), -1, mbox,getUsername(),getPassword());
// Properties props = System.getProperties();
// props.put("mail.smtp.host",getHostname());
// Session session = Session.getDefaultInstance(props,null);
// Store store = session.getStore(url);
// store.connect();

try{
// store.connect(server,port,username,password);
store.connect();
}catch(MessagingException e){
throw new Exception("Cannot log on to server.Please verify the username and password.");
}
try{
String mbox = "INBOX";
Folder folder = store.getFolder(mbox);
folder.open(Folder.READ_ONLY);

Message[] messages = folder.getMessages();

for(int i=0;i<messages.length;i++){
InternetAddress[] from = (InternetAddress[])messages[i].getFrom();
InternetAddress[] to = (InternetAddress[])messages[i].
getRecipients(Message.RecipientType.TO);
%>
<p>To <%= to[0].getAddress() %>, from <%= from[0].getAddress() %>,
subject <%= messages[i].getSubject() %> </p>
<%
}
}catch(MessagingException e){
throw new Exception("Cannot read message.Please verify your E-mail server has a valid inbox");
}finally{
store.close();
}
%>
回复
scud 2002-05-27
Properties aProperties = System.getProperties();
aProperties.put("mail.transport.protocol","smtp");
aProperties.put("mail.smtp.host","smtp.xxx.com");
aProperties.put("mail.smtp.port", "9025");


Session session = Session.getInstance(aProperties,null);

MimeMessage message = new MimeMessage(session);
回复
scud 2002-05-27
Properties aProperties = System.getProperties();
aProperties.put("mail.transport.protocol","smtp");
aProperties.put("mail.smtp.host","smtp.xxx.com");
pros.put("mail.smtp.port", "8025");


Session session = Session.getInstance(aProperties,null);

MimeMessage message = new MimeMessage(session);
回复
bxh777 2002-05-26
在线等待……
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告