Hi All
The code below sends a mail containing meeting details which would then alert the receipient 15 minutes prior to the meeting which is usually used in outlook for sent reminder meeting mails
import com.sun.mail.smtp.SMTPMessage;
import java.net.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.lang.reflect.*;
import java.util.*;
public class MailCal {
public static void main(String[] args) {
try {
String host = "HOST_MAIL_SERVER";
String from = "abc@xyz.com";
String to = "def@mnop.com";
String subject = "Hello Test Mail";
String summary = "Test Summary";
String description = "Test description";
String location = "Test Location";
String startTime=DateFormat.DTSTART(14, 45, 00);
String endTime=DateFormat.DTEND(14, 45, 00);
String timeStamp=DateFormat.DTSTAMP();
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getInstance(props, null);
// Define message
Message message = new SMTPMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
StringBuffer sb = new StringBuffer();
StringBuffer buffer = sb.append(
"BEGIN:VCALENDAR\n" +
"PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
"ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" + to + "\n" +
"ORGANIZER:MAILTO:" + from + "\n" +
startTime+"\n" +
endTime+"\n" +
"LOCATION:"+location+"\n" +
"TRANSP:OPAQUE\n" +
"SEQUENCE:0\n" +
"UID:040000008200E00074C5B7101A82E0080000000090257066F793C8010000000000000000100\n" +
"00000D80527697E8B3141AD210B23E76A64DC\n" +
timeStamp+"\n" +
"DESCRIPTION:"+description+"\n" +
"SUMMARY:"+summary+"\n" +
"PRIORITY:5\n" +
"X-MICROSOFT-CDO-IMPORTANCE:1\n" +
"CLASS:PUBLIC\n" +
"BEGIN:VALARM\n" +
"TRIGGER:-PT15M\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:Reminder\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR");
message.setHeader("X-Mailer", "Microsoft Office Outlook 11");
message.setHeader("Thread-Index", "AciZKuIpKjKRy3quQ+abmMVR7WMt8Q==");
message.setHeader("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.3138");
message.setContent(buffer.toString(), "text/calendar; method=REQUEST;charset=\"UTF-8\"");
// send message
Transport.send(message);
} catch (MessagingException me) {
me.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Another code that would format the dates used in the message is DateFormat.java...
import java.util.*;
/**
*
* @author akash
*/
public class DateFormat {
static int year = 0;
static int month = 0;
static int day = 0;
static int hour = 0;
static int min = 0;
static int second = 0;
static String month_str = "";
static String day_str = "";
static String hour_str = "";
static String min_str = "";
static String sec_str = "";
static Calendar cal = Calendar.getInstance();
public static String appendZero(int x) {
String str = "";
if (x < 10) {
str = "0" + x;
} else {
str = "" + x;
}
return str;
}
public static String format() {
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH);
day = cal.get(Calendar.DAY_OF_MONTH);
hour = cal.get(Calendar.HOUR_OF_DAY);
min = cal.get(Calendar.MINUTE);
second = cal.get(Calendar.SECOND);
if (month < 9) {
month++;
month_str = "0" + month;
} else {
month++;
month_str = "" + month;
}
day_str = appendZero(day);
hour_str = appendZero(hour);
min_str = appendZero(min);
sec_str = appendZero(second);
return (year + month_str + day_str + "T" + hour_str + min_str + sec_str + "Z");
}
public static void setting(int hr, int min, int sec){
cal.setTimeZone(TimeZone.getTimeZone("IST"));
cal.set(Calendar.HOUR_OF_DAY, hr);
cal.set(Calendar.MINUTE, min);
cal.set(Calendar.SECOND, sec);
cal.getTimeInMillis();
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
}
public static String DTSTART(int hr, int min, int sec) {
setting(hr,min,sec);
return ("DTSTART:" + format());
}
public static String DTSTAMP() {
cal.setTimeZone(TimeZone.getTimeZone("IST"));
return ("DTSTAMP:" + format());
}
public static String DTEND(int hr, int min, int sec) {
setting(hr,min,sec);
return ("DTEND:" + format());
}
}
Now for the problem that i am facing
This seems to be working fine in outlook 2007 very well . But in outlook 2003 I have seen that Only the plain text containing the headers and the content can be seen and there is no meeting reminder being made..
Kindly provide some inputs so that it would work in outlook 2003.
Thanks,
Akash