Topic: 请教高手,我的程序哪有问题? 谢 (JavaMail SMTP 发信权限验证) |
Print this page |
1.请教高手,我的程序哪有问题? 谢 (JavaMail SMTP 发信权限验证) | Copy to clipboard |
Posted by: fatboy2 Posted on: 2003-05-24 10:29 一个简单到极点的程序 可发不出去邮件 import java.util.*; import java.io.*; import java.text.*; import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; class SendMail {public static void main(String[] args){ String msg; String response; try { String port="25"; String host="smtp.mail.yahoo.com.cn"; Socket cs = new Socket(InetAddress.getByName(host),Integer.parseInt(port)); BufferedWriter outData = new BufferedWriter(new OutputStreamWriter(cs.getOutputStream())); // BufferedReader inData=new BufferedReader(new InputStreamReader(cs.getInputStream())); msg="HELO "+host; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); outData.flush(); String fromAddress="a_meng2001@sohu.com"; msg = "MAIL FROM:<" + fromAddress + ">" ; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); outData.flush(); String toAddress="a_meng2001@sohu.com"; msg="RCPT TO:<" + toAddress + ">"; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); outData.flush(); msg = "DATA"; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); outData.flush(); Date sentDate = new Date(); SimpleDateFormat formatter1= new SimpleDateFormat("EEE,d MMM yyyy hh:mm:ss z"); msg = "Date: " + formatter1.format(sentDate); System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); //outData.flush(); msg="From: "+ fromAddress; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); //outData.flush(); msg="To: "+toAddress; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); //outData.flush(); String subject="help"; msg = "Subject: "+subject ; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); //outData.flush(); String content="hello"; msg = content; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); //outData.flush(); outData.write('\r'); outData.write('\n'); outData.write('.'); outData.write('\r'); outData.write('\n'); outData.flush(); msg="QUIT" ; System.out.println(msg); for(int i=0;i<msg.length();i++) outData.write(msg.charAt(i)); outData.write('\r'); outData.write('\n'); outData.flush(); outData.close(); cs.close(); } catch(IOException ex){ ex.printStackTrace(); } } } |
2.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: nothing Posted on: 2003-05-24 10:35 楼上的,是不是smtp.mail.yahoo.com.cn不支持使用smtp的方式了啊。 试试别的smtp站点,比如: smtp.mail.yahoo.com 或是。。 |
3.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: fatboy2 Posted on: 2003-05-24 10:40 谢了,, 我只想知道我的程序是不是有问题 我换过了也不行 比如 stmp.mail.sohu.com |
4.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: fatboy2 Posted on: 2003-05-24 11:28 哪位大侠有时间帮我看看了。。 一个java 小菜鸟在哭泣了 这是我的网络编程的开始, 55555,挫折呀 |
5.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: why Posted on: 2003-05-24 11:34 程式应该没有问题 让小的试试看…… 真的没问题哟! 那么多半是大侠的SMTP不行啦! 大侠的ISP是否需要auth呢? |
6.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: fatboy2 Posted on: 2003-05-24 11:39 楼上的搞错了, 我不是大侠,只是小菜鸟 isp为何物?? 什么叫需要 auth 版主救命了。。。。 我忙了两天了,这个小程序就是不干活 |
7.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: nothing Posted on: 2003-05-24 11:45 就是说,有些smtp服务器,是要发信权限验证的,不是你发到那个25端口就可以了的. |
8.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: fatboy2 Posted on: 2003-05-24 11:49 噢,我也这样想过。。 但是如何解决这样的问题呢。。。 书上没说过。。。 |
9.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: fatboy2 Posted on: 2003-05-24 13:16 多谢楼上大侠们的指点。 关于这个问题,我已经明白了 smtp 是需要认证的。。。 详细情况在 http://www.cn-java.com/target/news.php?news_id=1511 |
10.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: nothing Posted on: 2003-05-24 22:22 用javamail进行认证发信 阅读次数4016 |
11.Re:请教高手,我的程序哪有问题? 谢 [Re: fatboy2] | Copy to clipboard |
Posted by: chenyajun5 Posted on: 2003-06-02 22:07 请附上详细代码啦,谢谢!! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |