请问一下,我用javamail发邮件连续发了两封邮件,为什么只有第一封邮件收到啊?

解决方案 »

  1.   

    import java.util.Properties;import javax.mail.*;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMultipart;import java.util.Date;public class SendMail { private Session sendMailSession = null; private String mailtype = "text/html;charset=GBK"; public void sendMail(String mailContent) {
    getSession(); Message newMessage = new MimeMessage(sendMailSession);
    try {
    newMessage.setFrom(new InternetAddress("[email protected]")); InternetAddress[] to = new InternetAddress[1];
    to[0] = new InternetAddress("[email protected]"); // 接收方邮件地址 newMessage.setRecipients(Message.RecipientType.TO, to); // 接收方邮件地址 String subject = "加盟商户";
    newMessage.setSubject(subject); // newMessage.setText(mailContent); // 邮件正文 不支持html Multipart mp = new MimeMultipart(); // Multipart对象,邮件内容,标题,附件等内容均添加到其中后再生成MimeMessage对象
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setContent(mailContent, mailtype);
    mp.addBodyPart(mbp1);
    newMessage.setContent(mp);// 设置内容
    newMessage.setSentDate(new Date(System.currentTimeMillis())); Transport.send(newMessage); } catch (AddressException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    } catch (MessagingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    } } /**
     * 获得一个会话
     * 
     * @return
     */
    public Session getSession() {
    if (sendMailSession == null) {
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.host", "smtp.sina.com"); // smtp主机名。
    props.put("mail.smtp.user", "zhcw_jiameng"); // smtp主机名。
    props.put("mail.smtp.port", "25");
    props.put("mail.smtp.password", "**********"); // 邮件密码。
    PopupAuthenticator popA = new PopupAuthenticator(); // 邮件安全认证。
    popA.performCheck("zhcw_jiameng", "**********"); // 填写用户名及密码
    sendMailSession = Session.getInstance(props, popA);
    sendMailSession.setDebug(false);
    }
    return sendMailSession;
    }}