admin管理员组

文章数量:1634812

SMTP,POP3,IMAP

POP3

POP3是Post Office Protocol 3的简称,即邮局协议的第3个版本,它规定怎样将个人计算机连接到Internet的邮件服务器和下载电子邮件的电子协议。它是因特网电子邮件的第一个离线协议标准,POP3允许用户从服务器上把邮件存储到本地主机(即自己的计算机)上,同时删除保存在邮件服务器上的邮件,而POP3服务器则是遵循POP3协议的接收邮件服务器,用来接收电子邮件的。

SMTP

SMTP 的全称是“Simple Mail Transfer Protocol”,即简单邮件传输协议。它是一组用于从源地址到目的地址传输邮件的规范,通过它来控制邮件的中转方式。SMTP 协议属于 TCP/IP 协议簇,它帮助每台计算机在发送或中转信件时找到下一个目的地。SMTP 服务器就是遵循 SMTP 协议的发送邮件服务器。

SMTP 认证,简单地说就是要求必须在提供了账户名和密码之后才可以登录 SMTP 服务器,这就使得那些垃圾邮件的散播者无可乘之机。

增加 SMTP 认证的目的是为了使用户避免受到垃圾邮件的侵扰。

IMAP

IMAP全称是Internet Mail Access Protocol,即交互式邮件存取协议,它是跟POP3类似邮件访问标准协议之一。不同的是,开启了IMAP后,您在电子邮件客户端收取的邮件仍然保留在服务器上,同时在客户端上的操作都会反馈到服务器上,如:删除邮件,标记已读等,服务器上的邮件也会做相应的动作。所以无论从浏览器登录邮箱或者客户端软件登录邮箱,看到的邮件以及状态都是一致的。

网易常见邮箱服务器信息:

腾讯邮箱服务器信息:stmp.qq

Action

public class MailAction extends ActionSupport {

private SysuserinfoService sysuserinfoService;// 用户基本信息表

private String email;

private String errorMessage;

private Sysuserinfo sysuserinfo;

/**

* 发邮件

*

* @return

*/

public String sendMail() {

System.out.println("LOG : MailAction-sendMail");

if (sysuserinfo == null) {

errorMessage = "获取用户信息失败,请返回登录界面重新尝试 !";

return "error";

}

String userId = sysuserinfo.getUserCode();

String userRole = sysuserinfo.getSysrole().getRoleCode();

Sysuserinfo userinfo = sysuserinfoService.findById(Sysuserinfo.class,

userId);

if (userinfo == null) {

errorMessage = "用户不存在,请返回登录界面重新尝试 !";

return "error";

}

// 设置邮件内容 String content = "尊敬的用户:" + userinfo.getUserName() +

String content = ".作业在线系统找回密码给你发的密码是:" + userinfo.getPassword()

+ "请注意自己的帐号安全,不要外泄密码!!";

boolean flag = false;

email = userinfo.getEmail();// 从数据库读出

if (email == null) {

errorMessage = "对不起,您还没有设置邮箱哦!";

return "error";

}

System.out.println("LOG : email = " + email);

flag = sendEmail(email, content);

if (!flag) {

errorMessage = "邮件发送过程中找不到家了!";

return "error";

}

return "success";

}

/**

* 账户:cn_edu_nwsuaf_mas@163 密码:cn.edu.nwsuaf 授权密码:cnedunwsuaf2017

*

* @param email

* @param content

* @return

*/

public boolean sendEmail(String email, String content) {

SimpleEmail mailUtil = new SimpleEmail();

/**

* 根据发送方设置服务器

*

*/

mailUtil.setHostName("smtp.163");

if (mailUtil.getHostName() == null) {

System.out.println("LOG : can not deal with the type of email!");

return false;

}

mailUtil.setAuthentication("xxxxxxxx@163",

"xxxxxxxx@163的授权码");

mailUtil.setCharset("utf-8");

try {

mailUtil.addTo(email);

mailUtil.setFrom("xxxxxxxx@163");

mailUtil.setSubject("subject");

mailUtil.setMsg(content);

mailUtil.send();

} catch (EmailException e) {

System.out.println("LOG : 邮件发送过程中找不到家了!");

e.printStackTrace();

return false;

}

return true;

}

Struts.xml

class="cn.edu.nwsuafAction.MailAction">

/page/mail/success.jsp

/page/mail/error.jsp

/login.jsp

本文标签: 邮箱密码世界Java