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

bxh777 2002-05-26 06:25:17
加精
邮件代理服务器默认端口为25,如何更改呢?
...全文
365 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
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
  • 打赏
  • 举报
回复
在线等待……

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧