請問在SMTP中利用Socket發送時﹐怎樣發送附件呢﹖謝謝﹗﹗ 用javamail 你看看它的例子,你是台湾人么?用繁体字?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to->hexiaofeng(java爱好者) :在什么地方工作呢﹖ 我建议你看看你所接收到的邮件的源代码。很容易就能够看出来他的语法的,具体的话你还是得去看看rfc得东西 请看 rfc 文档http://www.china-pub.com/computers/eMook/emooknew/RFC/rfc.asp DataInputStream in=new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream (socket.getOutputStream)); out.writeBytes("HELO "+"smtp.21cn.com"); out.writeBytes("\n"); String resu=in.readLine() ; System.out.println(resu) ; out.writeBytes("MAIL FROM:"+"[email protected]"); out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("RCPT TO:"+"[email protected]"); out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("DATA"); out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("Subject:"+"aa"); out.writeBytes("\n"); out.writeBytes("From:"+"[email protected]"); out.writeBytes("\n"); out.writeBytes("To:"+"[email protected]"); out.writeBytes("\n"); out.writeBytes("Content-Type: text/plain"+'\n'); out.writeBytes("Content-Transfer-encoding: 8bit" + '\n'); out.writeBytes("\n"); out.writeBytes("Content-Type: multipart/mixed;"+ " boundary=\"ddd\""+'\n'); out.writeBytes("--ddd"+'\n'); String aaa="d:\\abc.txt"; out.writeBytes("Content-Type: text/plain;"+"name="+"\""+aaa+"\""+""); out.writeBytes("\n"); out.writeBytes("Content-Transfer-Encoding: quoted-printable"+"\n") ; out.writeBytes("Content-Disposition: attachment;"+ "filename="+"\""+aaa+"\""+"\n") ; File file=new File("d:\\abc.txt"); BufferedInputStream input=new BufferedInputStream(new FileInputStream (file)); int result; while ((result=input.read())!=-1) { out.write(result) ; } out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("--ddd--"+'\n'); out.writeBytes("."); out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("QUIT"); resu=in.readLine(); System.out.println(resu) ; socket.close() ; }catch(Exception e){ System.out.println("closing...."); e.printStackTrace() ; }以上是我的部分程序﹐為什么我發送過去的附件信息就是不能在郵件中于附件形式顯示呢﹖謝謝﹗﹗ DataInputStream in=new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); out.writeBytes("HELO "+"smtp.21cn.com"); out.writeBytes("\n"); String resu=in.readLine() ; System.out.println(resu) ; out.writeBytes("MAIL FROM:"+"[email protected]"); out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("RCPT TO:"+"[email protected]"); out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("DATA"); out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("Subject:"+"aa"); out.writeBytes("\n"); out.writeBytes("From:"+"[email protected]"); out.writeBytes("\n"); out.writeBytes("To:"+"[email protected]"); out.writeBytes("\n"); out.writeBytes("Content-Type: text/plain"+'\n'); out.writeBytes("Content-Transfer-encoding: 8bit" + '\n'); out.writeBytes("\n"); out.writeBytes("Content-Type: multipart/mixed;"+ " boundary=\"ddd\""+'\n'); out.writeBytes("--ddd"+'\n'); String aaa="d:\\ypf\\dd.txt"; out.writeBytes("Content-Type: text/plain;"+"name="+"\""+aaa+"\""+""); out.writeBytes("\n"); out.writeBytes("Content-Transfer-Encoding: quoted-printable"+"\n") ; out.writeBytes("Content-Disposition: attachment;"+ "filename="+"\""+aaa+"\""+"\n") ; File file=new File("d:\\ypf\\dd.txt"); BufferedInputStream input=new BufferedInputStream(new FileInputStream (file)); int result; while ((result=input.read())!=-1) { out.write(result) ; } out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("--ddd--"+'\n'); out.writeBytes("."); out.writeBytes("\n"); resu=in.readLine(); System.out.println(resu) ; out.writeBytes("QUIT"); resu=in.readLine(); System.out.println(resu) ; socket.close() ; }catch(Exception e){ System.out.println("closing...."); e.printStackTrace() ; } }}以上是我的部分程序﹐為什么我的附件信息發過去后﹐就是不能用附件形式顯示呢﹖ 3行代码,求解释 一个秒表但是结束不了,用线程写的。求助啊。。。 手机卡刷卡,代替一卡通系统的开发 关于html标签中的radio select seq_aa.nextval from dual;我在jdbc里如何把该直取回并变成long型? java菜鸟,想请教面向对象开发如何学通学精 JNA回调函数的使用 初到贵版,先散一百,呵呵 关于jdbc异常:java.sql.SQLException: No data found 郁闷 医药造假监控系统---期末project求教 z-axix 专业的计算机书籍翻译与创作,欢迎加盟! 一个关于tomcat的问题
具体的话你还是得去看看rfc得东西
http://www.china-pub.com/computers/eMook/emooknew/RFC/rfc.asp
DataOutputStream out = new DataOutputStream (socket.getOutputStream)); out.writeBytes("HELO "+"smtp.21cn.com");
out.writeBytes("\n");
String resu=in.readLine() ;
System.out.println(resu) ; out.writeBytes("MAIL FROM:"+"[email protected]");
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ; out.writeBytes("RCPT TO:"+"[email protected]");
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ; out.writeBytes("DATA");
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ; out.writeBytes("Subject:"+"aa");
out.writeBytes("\n"); out.writeBytes("From:"+"[email protected]");
out.writeBytes("\n"); out.writeBytes("To:"+"[email protected]");
out.writeBytes("\n"); out.writeBytes("Content-Type: text/plain"+'\n');
out.writeBytes("Content-Transfer-encoding: 8bit" + '\n');
out.writeBytes("\n");
out.writeBytes("Content-Type: multipart/mixed;"+
" boundary=\"ddd\""+'\n');
out.writeBytes("--ddd"+'\n');
String aaa="d:\\abc.txt";
out.writeBytes("Content-Type: text/plain;"+"name="+"\""+aaa+"\""+"");
out.writeBytes("\n"); out.writeBytes("Content-Transfer-Encoding: quoted-printable"+"\n") ;
out.writeBytes("Content-Disposition: attachment;"+
"filename="+"\""+aaa+"\""+"\n") ; File file=new File("d:\\abc.txt");
BufferedInputStream input=new BufferedInputStream(new FileInputStream
(file));
int result;
while ((result=input.read())!=-1)
{
out.write(result) ;
}
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ; out.writeBytes("--ddd--"+'\n');
out.writeBytes(".");
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ;
out.writeBytes("QUIT");
resu=in.readLine();
System.out.println(resu) ;
socket.close() ;
}catch(Exception e){
System.out.println("closing....");
e.printStackTrace() ;
}
以上是我的部分程序﹐為什么我發送過去的附件信息就是不能在郵件中于附件形式顯示呢﹖謝謝﹗﹗
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeBytes("HELO "+"smtp.21cn.com");
out.writeBytes("\n");
String resu=in.readLine() ;
System.out.println(resu) ;
out.writeBytes("MAIL FROM:"+"[email protected]");
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ;
out.writeBytes("RCPT TO:"+"[email protected]");
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ;
out.writeBytes("DATA");
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ;
out.writeBytes("Subject:"+"aa");
out.writeBytes("\n");
out.writeBytes("From:"+"[email protected]");
out.writeBytes("\n"); out.writeBytes("To:"+"[email protected]");
out.writeBytes("\n");
out.writeBytes("Content-Type: text/plain"+'\n');
out.writeBytes("Content-Transfer-encoding: 8bit" + '\n');
out.writeBytes("\n");
out.writeBytes("Content-Type: multipart/mixed;"+
" boundary=\"ddd\""+'\n');
out.writeBytes("--ddd"+'\n');
String aaa="d:\\ypf\\dd.txt";
out.writeBytes("Content-Type: text/plain;"+"name="+"\""+aaa+"\""+"");
out.writeBytes("\n");
out.writeBytes("Content-Transfer-Encoding: quoted-printable"+"\n") ;
out.writeBytes("Content-Disposition: attachment;"+
"filename="+"\""+aaa+"\""+"\n") ; File file=new File("d:\\ypf\\dd.txt");
BufferedInputStream input=new BufferedInputStream(new FileInputStream
(file));
int result;
while ((result=input.read())!=-1)
{
out.write(result) ;
}
out.writeBytes("\n");
resu=in.readLine();
System.out.println(resu) ;
out.writeBytes("--ddd--"+'\n');
out.writeBytes(".");
out.writeBytes("\n"); resu=in.readLine();
System.out.println(resu) ;
out.writeBytes("QUIT");
resu=in.readLine();
System.out.println(resu) ;
socket.close() ;
}catch(Exception e){
System.out.println("closing....");
e.printStackTrace() ;
}
}
}
以上是我的部分程序﹐為什么我的附件信息發過去后﹐就是不能用附件形式顯示呢﹖