再整理一段javamail的发信代码

        Properties p = new Properties();
        p.put("mail.smtp.host", smtpHost);
        p.put("mail.smtp.port", "25");
        p.put("mail.smtp.auth", "false");
        Session session = Session.getInstance(p, null);
        session.setDebug(true);

        MimeMessage  mimeMessage = new MimeMessage (session);
        mimeMessage.setFrom(new InternetAddress(from));
        mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        mimeMessage.setSubject(title);

        mimeMessage.setText(content, "utf-8", "html");
        mimeMessage.setSentDate(new Date());
        mimeMessage.saveChanges();

        Transport.send(mimeMessage);

 

你可能感兴趣的:(javamail)