Mail-smtp-pop3.zip

  • dsqpan
    了解作者
  • Java
    开发工具
  • 7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2021-02-21 09:19
    上传日期
Mail-smtp-pop3(java收发邮件)
Mail-smtp-pop3.zip
  • Mail-smtp-pop3
  • pop3
  • POP3Demo.class
    2.3KB
  • POP3Demo.java
    1.6KB
  • smtp
  • SMTPDemo.java
    4.7KB
  • SMTPDemo.class
    5.6KB
  • .project
    380B
  • .classpath
    226B
内容介绍
package smtp; 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 com.sun.org.apache.xerces.internal.impl.dv.util.Base64; public class SMTPDemo { String mailServer; String from; String pass; String to; String content; String lineFeet = "\r\n"; private int port = 25; Socket client; BufferedReader in; DataOutputStream os; public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getMailServer() { return mailServer; } public void setMailServer(String mailServer) { this.mailServer = mailServer; } public String getFrom() { return from; } public void setFrom(String from) { this.from = from; } public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; } public String getTo() { return to; } public void setTo(String to) { this.to = to; } private boolean init() { boolean boo = true; if (mailServer == null || "".equals(mailServer)) { return false; } try { client = new Socket(mailServer, port); in = new BufferedReader(new InputStreamReader( client.getInputStream())); os = new DataOutputStream(client.getOutputStream()); String isConnect = response(); if (isConnect.startsWith("220")) { } else { System.out.println("建立连接失败:" + isConnect); boo = false; } } catch (UnknownHostException e) { System.out.println("建立连接失败!"); e.printStackTrace(); boo = false; } catch (IOException e) { System.out.println("读取流失败!"); e.printStackTrace(); boo = false; } return boo; } private String sendCommand(String msg) { String result = null; try { os.writeBytes(msg); os.flush(); result = response(); } catch (IOException e) { e.printStackTrace(); } return result; } private String response() { String result = null; try { result = in.readLine(); } catch (IOException e) { e.printStackTrace(); } return result; } private void close() { try { os.close(); in.close(); client.close(); } catch (IOException e) { e.printStackTrace(); } } public boolean sendMail() { if (client == null) { if (init()) { } else { return false; } } if (from == null || from.isEmpty() || to == null || to.isEmpty()) { return false; } String result = sendCommand("HELO " + mailServer + lineFeet); if (isStartWith(result, "250")) { } else { System.out.println("握手失败:" + result); return false; } String auth = sendCommand("AUTH LOGIN" + lineFeet); if (isStartWith(auth, "334")) { } else { return false; } String user = sendCommand(new String(Base64.encode(from.getBytes())) + lineFeet); if (isStartWith(user, "334")) { } else { return false; } String p = sendCommand(new String(Base64.encode(pass.getBytes())) + lineFeet); if (isStartWith(p, "235")) { } else { return false; } String f = sendCommand("Mail From:<" + from + ">" + lineFeet); if (isStartWith(f, "250")) { } else { return false; } String toStr = sendCommand("RCPT TO:<" + to + ">" + lineFeet); if (isStartWith(toStr, "250")) { } else { return false; } String data = sendCommand("DATA" + lineFeet); if (isStartWith(data, "354")) { } else { return false; } StringBuilder sb = new StringBuilder(); sb.append("From:<" + from + ">" + lineFeet); sb.append("To:<" + to + ">" + lineFeet); sb.append("Subject:test" + lineFeet); sb.append("Date:2010/10/27 17:30" + lineFeet); sb.append("Content-Type:text/plain;charset=\"GB2312\"" + lineFeet); sb.append(lineFeet); sb.append(content); sb.append(lineFeet + "." + lineFeet); String conStr = sendCommand(sb.toString()); if (isStartWith(conStr, "250")) { } else { return false; } String quit = sendCommand("QUIT" + lineFeet); if (isStartWith(quit, "221")) { } else { return false; } close(); return true; } private boolean isStartWith(String res, String with) { return res.startsWith(with); } public static void main(String[] args) { SMTPDemo mail = new SMTPDemo(); mail.setMailServer("smtp.qq.com"); mail.setFrom("393628134@qq.com"); mail.setPass("199169"); mail.setTo("285484657@qq.com"); mail.setContent("hello,my name is zhujiahao."); boolean boo = mail.sendMail(); if (boo) System.out.println("邮件发送成功!"); else { System.out.println("邮件发送失败!"); } } }
评论
    相关推荐
    • 邮件发送
      NULL 博文链接:https://xjl712.iteye.com/blog/2185047
    • 邮件服务器
      最好用的邮件服务器软件,代发代收,多年用都很好。
    • 邮件服务器
      邮件服务器
    • java邮件
      java邮件
    • 发送邮件
      NULL 博文链接:https://brucefight.iteye.com/blog/771421
    • 邮件客户端
      根据计算机网络邮件传收的有关协议,smtp/pop等。通过java语言编写实现,可以实现邮件收,发,删除,附件添加等功能
    • VoiceMail 邮件客户端
      VoiceMail是一个邮件客户端;与传统的邮件客户端不同的是,VoiceMail去掉了一些繁琐的功能,专注于最主要的功能,像发送邮件、收取邮件等。此外,VoiceMail还有自己的特色,就是可以语音朗读邮件,还可以通过语音...
    • 邮件服务器 cmail
      邮件服务器软件CMailServer于2000年8月问世,是基于Windows平台的邮件服务器软件,支持互联网邮件收发、网页邮件收发(Webmail)、邮件杀毒、防垃圾邮件邮件过滤、邮件监视、邮件备份、邮件转发、多域名邮件收发和...
    • 邮件陷阱
      邮件陷阱 开发人员的电子邮件测试工具。 Mailtrap使您可以使用伪造的SMTP服务器和API执行自动电子邮件测试。 SMTP服务器在端口1025上启动 HTTP服务器从端口8025启动 用法 version : ' 3.7 ' services : mailtrap ...
    • 邮件服务器
      邮件服务器