CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

SMTP协议,返回正确,但为什么收不到邮件呢?

楼主butnet(子石长成 http://vsplay.spaces.live.com/)2006-03-18 09:50:14 在 Java / J2SE / 基础类 提问

import   java.io.*;  
  import   java.net.*;  
  class   sendmail  
  {  
  public   static   void   main(String   args[])throws   Exception  
  {  
  String   ip;  
  String   sstr;  
  String   from=new   String("From:   <");  
  String   to=new   String("To:   ");  
  byte[]   r=new   byte[500];  
  int   num;  
  Socket   s=new   Socket("smtp.163.com",25);  
  ip=s.getLocalAddress().toString();  
  ip=ip.substring(1);  
  System.out.println("本地IP:"+ip);  
  DataInputStream   in=new   DataInputStream(s.getInputStream());  
  DataOutputStream   out=new   DataOutputStream(s.getOutputStream());  
  String   lin;  
  lin=in.readLine();  
  System.out.println(lin);  
  if(lin.indexOf("220")==-1)  
  {System.out.println("连接服务器错误");System.exit(0);}  
  System.out.println("连接成功");//接收连接是返回信息  
  sstr=new   String("EHLO   ");  
  System.out.println("要连接的服务器:");  
  num=System.in.read(r);  
  sstr+=new   String(r,0,num);  
  out.write(sstr.getBytes());  
  out.flush();//发送HELO  
   
  lin=in.readLine();  
  System.out.println("发送:"+sstr+"返回:"+lin);  
  if(lin.indexOf("250")==-1)  
  {System.out.println("邮件会话失败");System.exit(0);}  
  sstr=new   String("MAIL   FROM:<");  
  System.out.println("发件人:");  
  num=System.in.read(r);  
  from+=new   String(r,0,num-2)+">\r\n";  
  sstr+=new   String(r,0,num-2)+">\r\n";  
  out.write(sstr.getBytes());  
  out.flush();//发送mail   from  
   
  lin=in.readLine();  
  System.out.println("发送:"+sstr+"返回:"+lin);  
  if(lin.indexOf("250")==-1)  
  {System.out.println("发件人地址错误");System.exit(0);}  
  sstr=new   String("RCPT   TO:");  
  System.out.println("收件人:");  
  num=System.in.read(r);  
  to+=new   String(r,0,num);  
  sstr+=new   String(r,0,num-2)+">\r\n";  
  out.write(sstr.getBytes());  
  out.flush();//发送rcpt   to  
   
  lin=in.readLine();  
  System.out.println("发送:"+sstr+"返回:"+lin);  
  if(lin.indexOf("250")==-1)  
  {System.out.println("收件人地址错误");System.exit(0);}  
   
  sstr=new   String("DATA\r\n");  
  out.write(sstr.getBytes());  
  out.flush();  
  lin=in.readLine();  
  System.out.println("发送:"+sstr+"返回:"+lin);  
  if(lin.indexOf("250")==-1)  
  {System.out.println("邮件内容传输失败");System.exit(0);}  
  sstr=new   String("Subject:   ");  
  System.out.println("主题:");  
  num=System.in.read(r);  
  sstr+=new   String(r,0,num);  
  sstr+=from;  
  sstr+=to;  
  System.out.println("内容:");  
  num=System.in.read(r);  
  sstr+=new   String(r,0,num);  
  sstr+="\r\n.\r\n";  
  out.write(sstr.getBytes());  
  out.flush();  
  lin=in.readLine();  
  System.out.println("发送邮件:\r\n"+sstr+"返回:"+lin);  
  if(lin.indexOf("250")==-1)  
  {System.out.println("发送邮件失败");System.exit(0);}  
  System.out.println("发送成功");  
  sstr=new   String("QUIT");  
  out.write(sstr.getBytes());  
  out.flush();  
  System.out.println("发送离开信息:"+sstr+"返回:"+lin);  
  if(lin.indexOf("250")==-1)  
  {System.out.println("关闭失败");System.exit(0);}  
  s.close();  
  }//main  
  }//class  
  /*  
  输入下面的:  
  smtp.163.com  
  user1@163.com  
  user2@163.com  
  标题   你好  
  内容   收到了吗?  
  返回的值是250,表示对了的噻.  
  但为什么我在WEB邮箱中找不到邮件.  
  用POP3也找不邮件.  
  这是为什么呢????  
  */ 问题点数:80、回复次数:7Top

1 楼butnet(子石长成 http://vsplay.spaces.live.com/)回复于 2006-03-18 10:00:47 得分 0

忍了,没人回答,不管了先自己顶一个.Top

2 楼greenteanet(扎扎实实打基础,保持一颗平常心。)回复于 2006-03-18 11:05:17 得分 40

楼主去下面这个网站看看,看能不能帮你解决问题。  
  http://www.huihoo.com/java/javamail/javamail_faq.htmlTop

3 楼butnet(子石长成 http://vsplay.spaces.live.com/)回复于 2006-03-21 14:46:01 得分 0

Message-ID:   <00a901c64cab$e629b750$d201a8c0@b10>  
  这个标签是什么意思Top

4 楼apple21(编姑娘的小花篮)回复于 2006-03-21 14:51:40 得分 0

smtp是发邮件的协议   收邮件要用pop协议Top

5 楼apple21(编姑娘的小花篮)回复于 2006-03-21 14:55:54 得分 40

import   javax.mail.*;  
  import   javax.swing.*;  
  import   java.util.*;  
  import   javax.mail.internet.*;  
  import   javax.activation.*;  
  import   java.awt.*;  
  import   java.io.*;  
  import   javax.mail.search.*;  
   
  public   class   POPM  
  {  
  public   static   void   main(String[]   args)    
  {  
                try{   Authenticator   auth   =   new   PopupAuthenticator();  
   
  Properties   props   =   new   Properties();  
  props.put("mail.store.protocol","pop3");  
  props.put("mail.host","pop3.163.com");  
                //   props.put("mail.pop3.auth",   "true");  
   
  Session   sess=Session.getInstance(props,null);  
   
  Store   store   =   sess.getStore("pop3");  
  store.connect("pop3.163.com","","");//第2个填你的信箱名   第3个添你的信箱密码  
   
  Folder   inbox   =   store.getFolder("INBOX");  
                 
  inbox.open(Folder.READ_ONLY);  
   
  Message[]   msgs=inbox.getMessages();  
                //   Message[]   msgs=inbox.search(new   FlagTerm(new   Flags(Flags.Flag.DELETED),false));  
                                  for(int   i=0;i<mags.length;i++)  
                                {  
                                  System.out.println("msg     "+msgs[i].getMessageNumber());  
                                  System.out.println("Sent     "+msgs[i].getSentDate());  
                                  System.out.println("From     "+msgs[i].getFrom()[0]);  
                                  System.out.println("Subject     "+msgs[i].getSubject());  
   
                                    if(msgs[i].getContent()   instanceof   MimeMultipart)  
                                    {  
                                      MimeMultipart   mp=(MimeMultipart)msgs[i].getContent();  
                                      for(int   j=0,count=mp.getCount();j<count;j++)  
                                          {  
                                                Part   p=mp.getBodyPart(j);  
                                                System.out.println("########################"+"BEGIN       MIME"+"################################");  
                                                System.out.println(p.getContent());  
                                                System.out.println("########################"+"END       MIME"+"################################");  
                                            }  
                                          }  
   
                                      else  
                                            {  
                                                System.out.println("########################"+"BEGIN       content"+"################################");  
                                                System.out.println(msgs[i].getContent());  
                                                System.out.println("########################"+"END         content"+"################################");  
                                            }  
                                    }  
                    System.out.println("*******************************************************************");  
                  System.out.println("总共"+msgs.length+"封信笺");  
   
  inbox.close(false);  
  store.close();  
                   
                  //inbox.setFlags(msgs,new   Flags(Flags.Flag.DELETED),true);  
     
        }catch(MessagingException   m)  
                                              {  
                                                  m.printStackTrace();  
                                              }catch(IOException   io)  
                              {  
          io.printStackTrace();  
      }  
      System.exit(0);  
  }  
  }  
  class   PopupAuthenticator   extends   Authenticator  
  {  
        public   PasswordAuthentication   getPasswordAuthentication()  
  {  
                String   name,password;  
        String   result   =   JOptionPane.showInputDialog("Enter   name   password");  
                StringTokenizer   st   =   new   StringTokenizer(result,",");  
                name   =   st.nextToken();  
        password   =   st.nextToken();  
   
        return   new   PasswordAuthentication(name,password);  
          }  
  }Top

6 楼butnet(子石长成 http://vsplay.spaces.live.com/)回复于 2006-03-24 09:48:03 得分 0

我不用javax.mail,我自己写类似的类!Top

7 楼butnet(子石长成 http://vsplay.spaces.live.com/)回复于 2006-03-24 09:51:35 得分 0

smtp是发邮件的协议   收邮件要用pop协议  
  这个我当然知道塞,我那个只是发邮件的程序。POP3收邮件的程序我写好了。  
  是SMTP发邮件的程序出了问题。Top

相关问题

  • 救命啊~~用smtp协议的dll组建实现的asp邮件程序的问题
  • 关于smtp协议
  • 关于 Pop3 和 Smtp 协议......
  • 有谁知道SMTP协议?
  • 用vc实现SMTP协议?
  • smtp协议的问题
  • win NT 下不能用JMAIL 正确发送邮件,需要一个SMTP补丁,谁知道到那里能下载得到
  • 谁知道 要求身份认证的 邮件传输协议, 比SMTP更复杂的,正式的名字叫什么?
  • 哪位高手知道邮件群发是用什么协议?肯定不是用SMTP.这个问题可能VB人员才懂.
  • 请问有没有人知道如何用winsocket编程实现在以太网中监听SMTP和POP3协议的邮件,谢谢!

关键词

  • 邮件
  • 协议
  • sstr
  • lin
  • inbox
  • 返回
  • props
  • pop
  • mail
  • 发送

得分解答快速导航

  • 帖主:butnet
  • greenteanet
  • apple21

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo