使用smtp协议来编写回复邮件和移动邮件(移动邮件:把收件箱的邮件移动到发件箱) 使用smtp协议来编写回复邮件和移动邮件(移动邮件:把收件箱的邮件移动到发件箱),转发邮件,求一例子,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 现在回复做出来了,希望大家可以去看看,这是我个人的建议,这样做,呵呵,package com.huy.SendMail;import java.util.*;import javax.mail.*;import javax.mail.internet.*;import com.hyq.test.SimpleAuthenticator;/** * 回复邮件 * @author Administrator * vvvv */public class SendMail { private static String server = "smtp.126.com";// smtp主机名。 private static String from = "[email protected]";// 发送方邮件地址 private static String pw = "199217";// 发送方邮件密码。 private static String to = "[email protected]"; // 接收方邮件地址 private static final String PROTOCOL = "pop3"; static String mailContent = "你他妈是猪啊";// 邮件正文 private static final String HOST_NAME = "pop.126.com"; public static void send() throws Exception { try { Properties props = new Properties(); Session sendMailSession; Store store; Transport transport; props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", server); props.put("mail.smtp.user", from); props.put("mail.smtp.password", pw); props.put("mail.pop.host", HOST_NAME); sendMailSession = Session.getInstance(props, new Authenticator() { public PasswordAuthentication getPasswordAuthentication() // 邮件安全认证。 { return new PasswordAuthentication(from, pw); } }); Message newMessage = new MimeMessage(sendMailSession); newMessage.setFrom(new InternetAddress(from)); newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); String returnSub= returnSub(props,"565"); if(returnSub==null){ returnSub="hello"; } newMessage.setSubject(returnSub); newMessage.setSentDate(new Date()); mailContent += new Date().toLocaleString(); newMessage.setText(mailContent); transport = sendMailSession.getTransport("smtp"); Transport.send(newMessage); } catch (MessagingException ex) { } } public static void main(String[] args) throws Exception { SendMail sml = new SendMail(); sml.send(); System.out.println("成功"); } public static String returnSub(Properties props,String subject) throws Exception { Session session = Session.getDefaultInstance(props, new SimpleAuthenticator(from, pw)); Store store = session.getStore(PROTOCOL); store.connect(HOST_NAME, from, pw); Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); Message[] messages = folder.getMessages(); for (int i = messages.length - 1; i >= 0; i--) { System.out.println(messages[i].getSubject().toString()); if(messages[i].getSubject().toString().equals(subject)){ return "回复:"+messages[i].getSubject().toString(); } } return null; }}关于移动文件夹,希望大家多多支持啊,小弟还没有想出来啊 移动文件夹smtp协议(应该)不支持,如1F所言,imap吧 能够具体点吗,这个imap协议,我找了很久都没有找到移动文件的做法,原理我看懂一些,就不知道如何下手 急求基于struts的新闻发布系统 异步日志记录、批量输出? 怎么使用wsdl4j解析wsdl文件? 百思不得其解-关于java开发环境配置,为什么找不到javax.ejb JavaWeb系统定时自动运行的问题 如何实现动态、抽象、继承、封装、接口 关于struts多文件上传!(求思路) 总服务器和各下级服务器实现数据同步的思想。 我编译tomcat自带的servlet范例java文件,为何老提示import javax.servlet.*;中的javax.servlet包不存在? JSP中调用EJB的问题--------- 【转】spring框架是否提高了可维护性? Java基础,求指点
package com.huy.SendMail;import java.util.*;import javax.mail.*;
import javax.mail.internet.*;import com.hyq.test.SimpleAuthenticator;
/**
* 回复邮件
* @author Administrator
* vvvv
*/
public class SendMail { private static String server = "smtp.126.com";// smtp主机名。
private static String from = "[email protected]";// 发送方邮件地址
private static String pw = "199217";// 发送方邮件密码。
private static String to = "[email protected]"; // 接收方邮件地址
private static final String PROTOCOL = "pop3";
static String mailContent = "你他妈是猪啊";// 邮件正文 private static final String HOST_NAME = "pop.126.com"; public static void send() throws Exception { try {
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", server);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pw);
props.put("mail.pop.host", HOST_NAME);
sendMailSession = Session.getInstance(props, new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() // 邮件安全认证。
{
return new PasswordAuthentication(from, pw);
}
});
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(from));
newMessage.setRecipient(Message.RecipientType.TO,
new InternetAddress(to));
String returnSub= returnSub(props,"565");
if(returnSub==null){
returnSub="hello";
}
newMessage.setSubject(returnSub);
newMessage.setSentDate(new Date());
mailContent += new Date().toLocaleString();
newMessage.setText(mailContent);
transport = sendMailSession.getTransport("smtp");
Transport.send(newMessage); } catch (MessagingException ex) { }
} public static void main(String[] args) throws Exception {
SendMail sml = new SendMail();
sml.send();
System.out.println("成功");
}
public static String returnSub(Properties props,String subject) throws Exception {
Session session = Session.getDefaultInstance(props,
new SimpleAuthenticator(from, pw));
Store store = session.getStore(PROTOCOL);
store.connect(HOST_NAME, from, pw);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message[] messages = folder.getMessages();
for (int i = messages.length - 1; i >= 0; i--) {
System.out.println(messages[i].getSubject().toString());
if(messages[i].getSubject().toString().equals(subject)){
return "回复:"+messages[i].getSubject().toString();
}
}
return null;
}
}关于移动文件夹,希望大家多多支持啊,小弟还没有想出来啊