-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static void send(String smtp, int port, String user,
- String password, String from, String to, String cc, String bcc,
- String subject, String body) throws Exception {
-
- Properties props = new Properties();
-
- props.put("mail.transport.protocol", "smtp");
- props.put("mail.smtp.auth", "true");
-
-
- Session mailSession = Session.getDefaultInstance(props, null);
- mailSession.setDebug(true);
-
-
- MimeMessage mimeMsg = new MimeMessage(mailSession);
-
-
- mimeMsg.setFrom(new InternetAddress(from));
-
- if (to != null) {
- mimeMsg.setRecipients(Message.RecipientType.TO, InternetAddress
- .parse(to));
- }
-
-
- if (cc != null) {
- mimeMsg.setRecipients(Message.RecipientType.CC, InternetAddress
- .parse(cc));
- }
-
-
- if (bcc != null) {
- mimeMsg.setRecipients(Message.RecipientType.BCC, InternetAddress
- .parse(bcc));
- }
-
- mimeMsg.setSubject(subject);
-
- mimeMsg.setContent(body, "text/html ;charset=gbk");
-
-
- Transport transport = mailSession.getTransport();
- transport.connect(smtp, port, user, password);
- transport.sendMessage(mimeMsg, mimeMsg.getAllRecipients());
- transport.close();
- }
|