以流的形式发送邮件很霸道的...

 

 
1.   学习了怎样通过以流的形式发送邮件在这里记下来。这里用到了 base64 Encoder 编码。在上一篇写到了如何编码这里就没有写了。
2.   代码如下:
3.   import java.io.BufferedReader;
4.   import java.io.IOException;
5.   import java.io.InputStreamReader;
6.   import java.io.OutputStream;
7.   import java.net.Socket;
 
8.   public class SocketTest {
9.   public static void main(String[] args) throws IOException {
 
10. Socket sk= new Socket( "smtp.sohu.com" ,25); //spmt 协议例如:搜狐 smpt.sohu.com
11. OutputStream os=sk.getOutputStream();
12. BufferedReader br= new BufferedReader( new InputStreamReader(sk.getInputStream()));
13. System. out .println(br.readLine());
14. os.write( "ehlo name/r/n" .getBytes()); // 计算机名称
15. System. out .println(br.readLine());
16. System. out .println(br.readLine());
17. System. out .println(br.readLine());
 
18. os.write( "auth login/r/n" .getBytes());
19. System. out .println(br.readLine());
 
20. os.write( "user/r/n" .getBytes());  // base64 Encoder 编码的搜狐用户名
21. System. out .println(br.readLine());
22. os.write( "pass/r/n" .getBytes()); // base64 Encoder 编码的搜狐密码
23. System. out .println(br.readLine());
 
24. os.write( "mail from:< 邮箱名 >/r/n" .getBytes()); // 自己搜狐的邮箱
25. System. out .println(br.readLine());
 
26. os.write( "rcpt to:< 邮箱名 >/r/n" .getBytes()); // 要接收用户的邮箱
27. System. out .println(br.readLine());
 
 
28. os.write( "data/r/n" .getBytes());
29. System. out .println(br.readLine());
30. os.write( "from:< 邮箱名 >/r/n" .getBytes()); // 自己搜狐的邮箱
31. os.write( "to:< 邮箱名 >/r/n" .getBytes()); // 要接收用户的邮箱
32. os.write( "subject: 你好 /r/n" .getBytes()); // 邮箱主题
33. os.write( "/r/n" .getBytes());
34. os.write( " 小李同志你好 /r/n" .getBytes()); // 邮箱内容
 
35. os.write( "./r/n" .getBytes()); // 以点结束邮箱内容
36. System. out .println(br.readLine());
37. os.write( "quit/r/n" .getBytes()); // 退出邮箱
 
 
 
38. br.close();
39. os.close();
40. sk.close();
 
 
 
41. }
42. }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值