java email

		Properties props = new Properties();
		props.put("mail.transport.protocol", "smtp");

		// create some properties and get the default Session
		Session session = Session.getDefaultInstance(props, null);

		// create a message
		Message msg = new MimeMessage(session);

		// set the from and to address
		InternetAddress addressFrom = new InternetAddress(from);

		InternetAddress[] addressTo = new InternetAddress[recipients.length];
		for (int i = 0; i < recipients.length; i++) {
			addressTo[i] = new InternetAddress(recipients[i]);
		msg.setRecipients(Message.RecipientType.TO, addressTo);

		// Optional : You can also set your custom headers in the Email if you
		// Want
		msg.addHeader("MyHeaderName", "myHeaderValue");

		// Create the message part 
		BodyPart messageBodyPart = new MimeBodyPart();

		// Fill the message
		if((Integer)results.get("recentRun") > 0) {
			msg.setSubject(MessageFormat.format(subject, ""));	
			//MessageFormat.format(subject, "is running");//dynamic properties placeholder ??
			messageBodyPart.setContent(MessageFormat.format((String) message,"",SYD.format(results.get("latestRun"))),"text/html");
		else {
			msg.setSubject(MessageFormat.format(subject, "NOT "));
			//MessageFormat.format(subject, "is not running");//dynamic properties placeholder ??
			messageBodyPart.setContent(MessageFormat.format((String) message,"<b><FONT COLOR='RED'>NOT</FONT></b> ",SYD.format(results.get("latestRun"))),"text/html");
		Multipart multipart = new MimeMultipart();

 * // Part two is attachment
		messageBodyPart = new MimeBodyPart();
		//DataSource source = new FileDataSource("C:\\OOLCheck\\OOLReport.pdf");
		DataSource source = new FileDataSource("OOLReport.pdf");
		messageBodyPart.setDataHandler(new DataHandler(source));

		messageBodyPart = new MimeBodyPart();
		//DataSource source2 = new FileDataSource("C:\\OOLCheck\\OOLReport_OEReport.pdf");
		DataSource source2 = new FileDataSource("OOLReport_OEReport.pdf");
		messageBodyPart.setDataHandler(new DataHandler(source2));


*/		// Put parts in message
		try {
			}catch(MessagingException e){

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s