以下是使用命令行来发送和接受邮件:
1、准备工作,因为邮件使用的用户名和密码是经过Base64编码的,所以我们先写一段准备的代码
 
 public static void main(String[] args) throws IOException {
  BASE64Encoder encoder = new BASE64Encoder();
  System.out.println("Please enter you userName:");
  String username = new BufferedReader(new InputStreamReader(System.in)).readLine();
  System.out.println(encoder.encode(username.getBytes()));
  
  System.out.println("Please enter you password:");
  String password = new BufferedReader(new InputStreamReader(System.in)).readLine();
  System.out.println(encoder.encode(password.getBytes()));
 }
 
发送的邮箱为 test@sina.com,接受的邮箱为 test@sohu.com, 密码均为123456
 
2、发送邮件过程:
链接到sina邮件服务器: telnet smtp.sina.com 25
向服务器打招呼: ehlo test
使用的登录方式或是验证方式: auth login
输入用户名:dGVzdA==  <用户名是经过BASE64加密后的>
输入密码:MTIzNDU2  <用户名是经过BASE64加密后的>
通过验证后,输入发件箱地址: mail from: < test@sina.com> 此为真正发送邮件的Email
收件箱地址: rcpt to: < test@sohu.com>
 
以下为邮件内容:
data
from: < haha@sina.com >  此为邮箱中所看到的发件人
subject :  hello world 
 
content12345haha  
.
 此为邮件内容,主题和内容之间必须要空一行,并且内容以 "." 结束
 
提示发送成功!
 
3、接受邮件
链接到sohu邮件服务器: telnet pop3.sohu.com 110
输入用户名: user test   (此用户名不需要加密)
输入密码: pass 123456  (此密码不需要加密)
登录成功后,使用list 列出所有邮件列表
使用retr N 查看第N封邮件
 
 
注:有可能接受邮件服务器会将邮件视为垃圾邮件!