msg.setText("Med vennlig hilsennTov Are Jacobsen"); msg.setHeader("X-Mailer", "Tov Are's program"); msg.setSentDate(new Date()); SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
public static void send(String smtpServer, String to, String from , String subject, String body) throws Exception { Properties props = System.getProperties(); // -- Attaching to default Session, or we could start a new one -- props.put("mail.smtp.host", smtpServer); Session session = Session.getDefaultInstance(props, null); // -- Create a new message -- Message msg = new MimeMessage(session); // -- Set the FROM and TO fields -- msg.setFrom(new InternetAddress(from)); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); // -- We could include CC recipients too -- // if (cc != null) // msg.setRecipients(Message.RecipientType.CC // ,InternetAddress.parse(cc, false)); // -- Set the subject and body text -- msg.setSubject(subject); msg.setText(body); // -- Set some other header information -- msg.setHeader("X-Mailer", "LOTONtechEmail"); msg.setSentDate(new Date()); // -- Send the message -- Transport.send(msg); System.out.println("Message sent OK."); }
msg.setHeader("List-Unsubscribe", "1"); msg.setSentDate(new Date());
msg.setText("Med vennlig hilsennTov Are Jacobsen"); msg.setHeader("X-Mailer", "Tov Are's program"); msg.setSentDate(new Date()); SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
msg.setSentDate(new Date());