• 大小: 25KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-07
  • 语言: Java
  • 标签: networking  

资源简介

Java实现邮件客户端,其中使用的协议是SMTP协议以及TCP协议,有需要的兄弟姐妹可以下载。

资源截图

代码片段和文件信息

package emailClient;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.base64;
import java.util.Scanner;

/**
 * 
 * @author sunyuhu
 * @category this is an email client.
 * @version v20180914
 */
public class Client {
public static void main(String[] args){
//新建一个tcp连接,和网易的
try {
Socket client = new Socket(“smtp.qq.com“25);
            BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
            String response = br.readLine();
            String username;                             //用户名
            String password;                             //密码
            String receiver;                             //接收用户名
            String subject;                              //邮件主题
            String str;
            StringBuffer content = new StringBuffer();
            if(response.equals(“220 smtp.qq.com Esmtp QQ Mail Server“)){
             System.out.println(“客户端已经连接到腾讯邮件服务器!!“);
            
             //输入EHLO指令
             DataOutputStream dos = new DataOutputStream(client.getOutputStream());
     dos.writeBytes(“HELO sunyuhu\r\n“);
     dos.flush();
             response = br.readLine();
             if(!response.equals(“250 smtp.qq.com“)){
               System.out.println(“命令错误!!!“);
             }
             
             //输入认证指令,用户名和密码
     dos.writeBytes(“AUTH LOGIN\r\n“);
     dos.flush();
             response = br.readLine();
             if(!response.equals(“334 VXNlcm5hbWU6“)){
               System.out.println(“命令错误!!!“);
                }else{
                 System.out.print(“请输入用户名:“);
                 Scanner sc = new Scanner(System.in);
                 username = sc.nextLine();
                 //base64.getEncoder().encodeToString(username.getBytes());
                 //dos.writeBytes(“MTI2Mzc1ODM4N0BxcS5jb20=\r\n“);
                 dos.writeBytes(base64.getEncoder().encodeToString(username.getBytes())+ “\r\n“);
         dos.flush();
                 response = br.readLine();
             if(!response.equals(“334 UGFzc3dvcmQ6“)){
                System.out.println(“用户名输入错误!!!“);
             }else{
                  System.out.println(“用户名输入成功!!!“);
                  System.out.print(“请输入密码:“);
                  sc = new Scanner(System.in);
                  password = sc.nextLine();
                  dos.writeBytes(“dm54dmJ2YWJpbXZwaGpjZQ==\r\n“);
          dos.flush();
                  response = br.readLine();
                  if(!response.equals(“235 Authentication successful“)){
                   System.out.println(“密码输入错误!!!“);
                  }else{
                   System.out.println(“登录成功!!!“);
                   System.out.print(“请输入收件人:“);
                  sc = new Scanner(System.in);
          

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        301  2018-09-14 22:42  ComputerNetworking\.classpath

     文件        394  2018-09-14 22:42  ComputerNetworking\.project

     文件        598  2018-09-14 22:42  ComputerNetworking\.settings\org.eclipse.jdt.core.prefs

     文件       4124  2018-09-14 22:42  ComputerNetworking\bin\emailClient\Client.class

     文件        807  2018-09-14 22:42  ComputerNetworking\bin\emailClient\Main$1.class

     文件       3878  2018-09-14 22:42  ComputerNetworking\bin\emailClient\Main$2.class

     文件       2565  2018-09-14 22:42  ComputerNetworking\bin\emailClient\Main.class

     文件       1141  2018-09-14 22:42  ComputerNetworking\bin\emailClient\WriteAndSendEmail$1.class

     文件       1087  2018-09-14 22:42  ComputerNetworking\bin\emailClient\WriteAndSendEmail$2.class

     文件       4471  2018-09-14 22:42  ComputerNetworking\bin\emailClient\WriteAndSendEmail$3.class

     文件       3622  2018-09-14 22:42  ComputerNetworking\bin\emailClient\WriteAndSendEmail.class

     文件       2423  2018-09-14 22:42  ComputerNetworking\bin\httpServer\HttpServer.class

     文件       1744  2018-09-14 22:42  ComputerNetworking\bin\udp\UDPClient.class

     文件       1518  2018-09-14 22:42  ComputerNetworking\bin\udp\UDPServer.class

     文件       4544  2018-09-14 22:42  ComputerNetworking\src\emailClient\Client.java

     文件       5763  2018-09-14 22:42  ComputerNetworking\src\emailClient\Main.java

     文件       7705  2018-09-14 22:42  ComputerNetworking\src\emailClient\WriteAndSendEmail.java

     文件       2261  2018-09-14 22:42  ComputerNetworking\src\httpServer\HttpServer.java

     文件       1083  2018-09-14 22:42  ComputerNetworking\src\udp\UDPClient.java

     文件        967  2018-09-14 22:42  ComputerNetworking\src\udp\UDPServer.java

     目录          0  2018-09-14 22:42  ComputerNetworking\bin\emailClient

     目录          0  2018-09-14 22:42  ComputerNetworking\bin\httpServer

     目录          0  2018-09-14 22:42  ComputerNetworking\bin\udp

     目录          0  2018-09-14 22:42  ComputerNetworking\src\emailClient

     目录          0  2018-09-14 22:42  ComputerNetworking\src\httpServer

     目录          0  2018-09-14 22:42  ComputerNetworking\src\udp

     目录          0  2018-09-14 22:42  ComputerNetworking\.settings

     目录          0  2018-09-14 22:42  ComputerNetworking\bin

     目录          0  2018-09-14 22:42  ComputerNetworking\src

     目录          0  2018-09-14 22:42  ComputerNetworking

............此处省略3个文件信息

评论

共有 条评论

相关资源