使用smtp协议来编写回复邮件和移动邮件(移动邮件:把收件箱的邮件移动到发件箱),转发邮件,求一例子,谢谢

解决方案 »

  1.   

        现在回复做出来了,希望大家可以去看看,这是我个人的建议,这样做,呵呵,
    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;
    }
    }关于移动文件夹,希望大家多多支持啊,小弟还没有想出来啊
      

  2.   

    移动文件夹smtp协议(应该)不支持,如1F所言,imap吧
      

  3.   

    能够具体点吗,这个imap协议,我找了很久都没有找到移动文件的做法,原理我看懂一些,就不知道如何下手