www.webdeveloper.com
Results 1 to 3 of 3

Thread: Sending MS Outlook Meeting Request

  1. #1
    Join Date
    Sep 2006
    Posts
    2

    Sending MS Outlook Meeting Request

    Hi all,

    Can someone please send me a working JAVA code that would send a Meeting Request to MS Outlook ?

    I Badly need this ASAP ...

    My id: mailvidi@gmail.com

    Thank You,
    Vidi

  2. #2
    Join Date
    Sep 2006
    Posts
    2
    Did this by ourselves.. I've been getting so many emails abt this.. so here's the code after 5 years

    Code:
    public void send(String uniqueId, Date reviewDateTime) throws Exception
    
    {
    
              String from = "123@456.com";
    
              String to = "456@456.com";
    
              String meetingStartTime = getReviewTime(reviewDateTime, false);
    
              String meetingEndTime = getReviewTime(reviewDateTime, true);
    
              Properties prop = new Properties();
    
              StringBuffer sb = new StringBuffer();
    
              StringBuffer buffer = null;
    
              Session session = Session.getDefaultInstance(prop, null);
    
              Message message = new MimeMessage(session);
    
     
    
              try {
    
                       prop.put("mail.smtp.host", "192.168.112.111");
    
                       prop.put("mail.smtp.port", "25");
    
     
    
                       // Define message
    
                       message.setFrom(new InternetAddress(from));
    
                       message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
    
                       message.setRecipients(Message.RecipientType.CC, InternetAddress.parse("123@456.com,456@456.com,789@456.com"));
    
                       message.setSubject("This is the subject of the Meeting Request");
    
                       message.setHeader("X-Mailer", "iQuest-Mailer");
    
     
    
                       // Create the message part
    
                       MimeBodyPart messageBodyPart = new MimeBodyPart();
    
                       buffer = sb.append("BEGIN:VCALENDAR\n"
    
                                                    + "PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n"
    
                                                    + "VERSION:2.0\n"
    
                                                    + "METHOD:REQUEST\n"
    
                                                    + "BEGIN:VEVENT\n"
    
                                                    + "ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:123@456.com\n"
    
                                                    + "ORGANIZER:MAILTO:456@456.com\n"
    
                                                    + "DTSTART:" + meetingStartTime + "\n"
    
                                                    + "DTEND:" + meetingEndTime + "\n"
    
                                                    + "LOCATION:Conference room\n"
    
                                                    + "TRANSP:OPAQUE\n"
    
                                                    + "SEQUENCE:0\n"
    
                                                    + "UID:" + uniqueId + "@456.com\n"
    
                                                    + "DTSTAMP:" + meetingEndTime + "\n"
    
                                                    + "CATEGORIES:Meeting\n"
    
                                                    + "DESCRIPTION:This the description of the meeting.\n\n"
    
                                                    + "SUMMARY:Test meeting request\n" + "PRIORITY:1\n"
    
                                                    + "CLASS:PUBLIC\n" + "BEGIN:VALARM\n"
    
                                                    + "TRIGGER:PT1440M\n" + "ACTION:DISPLAY\n"
    
                                                    + "DESCRIPTION:Reminder\n" + "END:VALARM\n"
    
                                                    + "END:VEVENT\n" + "END:VCALENDAR");
    
                       messageBodyPart.setFileName("meeting.ics");
    
                       messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(buffer.toString(), "text/iCalendar")));
    
                       messageBodyPart.setHeader("Content-Class","urn:content-classes:calendarmessage");
    
                       messageBodyPart.setHeader("Content-ID", "calendar_message");
    
                       Multipart multipart = new MimeMultipart();
    
                       multipart.addBodyPart(messageBodyPart);
    
                       message.setContent(multipart);
    
                       Transport.send(message);
    
              }
    
              catch (Exception e) {
    
                       e.printStackTrace();
    
    }
    
    }
    
     
    
    public String getReviewTime(Date reviewDateTime, boolean flag)
    
    {
    
    Calendar c = Calendar.getInstance();
    
              SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd");
    
              c.setTime(reviewDateTime);
    
              if (flag)
    
                       c.add(Calendar.MINUTE, 30);
    
              String hour = c.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
    
                                 + c.get(Calendar.HOUR_OF_DAY) : ""
    
                                 + c.get(Calendar.HOUR_OF_DAY);
    
              String min = c.get(Calendar.MINUTE) < 10 ? "0" + c.get(Calendar.MINUTE)
    
                                 : "" + c.get(Calendar.MINUTE);
    
              String sec = c.get(Calendar.SECOND) < 10 ? "0" + c.get(Calendar.SECOND)
    
                                 : "" + c.get(Calendar.SECOND);
    
     
    
              String date = s.format(new Date(c.getTimeInMillis()));
    
              String dateTime = date + "T" + hour + min + sec + "Z";
    
              return dateTime;
    
    }
    
     
    
    private class ByteArrayDataSource implements DataSource
    
    {
    
              private byte[] data; // data for mail message
    
     
    
              private String type; // content type/mime type
    
     
    
              ByteArrayDataSource(String data, String type)
    
    {
    
                       try
    
    {
    
                                 // Assumption that the string contains only ascii
    
                                 // characters ! Else just pass in a charset into this
    
                                 // constructor and use it in getBytes()
    
                                 this.data = data.getBytes("iso-8859-1");
    
                       }
    
    catch (Exception e)
    
    {
    
                                 e.printStackTrace();
    
                       }
    
                       this.type = type;
    
              }
    
              // DataSource interface methods
    
              public InputStream getInputStream() throws IOException
    
    {
    
                       if (data == null)
    
                                 throw new IOException("no data exception in ByteArrayDataSource");
    
                        return new ByteArrayInputStream(data);
    
              }
    
     
    
              public OutputStream getOutputStream() throws IOException
    
    {
    
                       throw new IOException("illegal operation in ByteArrayDataSource");
    
              }
    
     
    
              public String getContentType()
    
    {
    
                       return type;
    
              }
    
     
    
              public String getName()
    
    {
    
                       return "dummy";
    
              }
    
    }
    Regards,
    Vidi

  3. #3
    Join Date
    Mar 2012
    Posts
    1
    I tried many blogs but none of them could solve my problem. Though stand alone java programs were sending the meeting invites, but on trying to send from JBOSS webservice, they were throwing exceptions and were failing.
    Finally the code that worked for me was

    enter code here
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.UnsupportedEncodingException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Properties;

    import javax.activation.DataHandler;
    import javax.activation.DataSource;
    import javax.mail.BodyPart;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Multipart;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;


    public class SendMeetingMail{

    // the acceptance or rejection notification goes to this email address
    private String rsvpTo="ToEmail"; // eg: xxx@gmail.com
    private String fromEmail="RSVPEmail"; // eg: xxxyy@gmail.com

    private String toEmail;
    // meeting details are extracted from agendaDetails object passed in the constructor

    public SendMeetingMail(String toEmail)
    {
    this.toEmail = toEmail;
    }


    /**
    * The method that takes care of sending the meeting invite
    * @throws Exception the caller has to catch the exception to ascertain if there is an error while sending.
    */
    public void send() throws Exception {
    try {

    String date[] = "2011-09-30".split("-");
    String startTime[] = "09:10".split(":");
    String endTime[] = "10:10".split(":");

    String venue= "Your venue";
    String heading = "meeting heading";
    String summary = "meeting summary";

    Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "smtp");
    props.setProperty("mail.host", "smtp.gmail.com");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", "true");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class",
    "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");

    Session session = Session.getDefaultInstance(props,
    new CredentialAuthenticator());
    session.setDebug(true);
    Transport transport = session.getTransport();
    // another approach
    MimeMessage message = new MimeMessage(session);

    message.setFrom( new InternetAddress(fromEmail, rsvpTo) );
    javax.mail.Address address = new InternetAddress(toEmail,toEmail);
    message.addRecipient(MimeMessage.RecipientType.TO, address);
    message.setSubject(summary);

    String contentType = "text/plain";

    StringBuffer buffer = new StringBuffer();

    buffer.append("BEGIN:VCALENDAR\n" +
    "PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN\n" +
    "VERSION:1.0\n" +
    "BEGIN:VEVENT\n" +
    "ATTENDEE:MAILTO:xxx@gmail.com\n" +
    "DTSTART:"+date[0]+date[1]+date[2]+"T"+startTime[0]+startTime[1]+"00Z\n" +
    "DTEND:"+date[0]+date[1]+date[2]+"T"+endTime[0]+endTime[1]+"00Z\n" +

    "LOCATION;ENCODING=QUOTED-PRINTABLE:"+venue+"\n" +
    "UID:040000008200E00074C5B7101A82E008000000004024D79F7EFDC4010000000000000000100\n" +
    " 00000CA06303EA8D5AD408E07455F234F0294\n" +
    "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:Sent from Summit Application.=0D=0A\n" +
    "SUMMARY;ENCODING=QUOTED-PRINTABLE:"+heading+"\n" +
    "PRIORITY:3\n" +
    "END:VEVENT\n" +
    "END:VCALENDAR");

    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("Sent from Summit Application.");
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    messageBodyPart = new MimeBodyPart();
    String filename = "demo.vcs";
    messageBodyPart.setFileName(filename);
    messageBodyPart.setContent(buffer.toString(), "text/plain");

    // Add part two
    multipart.addBodyPart(messageBodyPart);

    // Put parts in message
    message.setContent(multipart);

    // send message
    // Connect, Send the Message, and Close the Connection
    transport.connect();
    transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
    transport.close();

    // Then print a success message - this is only for testing
    System.out.println("Message sent!");

    } catch (MessagingException me) {
    me.printStackTrace();
    // again throw it to ws
    throw me;
    } catch (Exception ex) {
    ex.printStackTrace();
    // again throw it to ws
    throw ex;

    }
    }


    private class CredentialAuthenticator extends javax.mail.Authenticator {
    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("xxx@gmail.com",
    "passcode");

    }
    }


    public static void main(String[] args) {
    try {
    String toEmail="dummyemail@gmail.com";
    SendMeetingMail obj = new SendMeetingMail(toEmail);
    obj.send();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }


    Hope this helps

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles