Hi,
I couldn’t say that I did it fully. The following code is sending the meeting request as an attachment. I am still looking where and how to make changes so that it sends a ‘complete meeting request’. I am posting the code here so that you and others also work together to comeout with a tangible java service that sends meeting request. May be this is a good time to do some R & D .
Create a java service and import the below packages:
[FONT=Courier New]import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringBufferInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;[/font]
[FONT=Courier New]import javax.mail.internet.MimeBodyPart.*;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;[/font]
[FONT=Courier New]import java.io.*;[/font]
[FONT=Courier New]import java.lang.*;[/font]
[FONT=Courier New]import java.util.*;[/font]
May be there are unused packages in the above list.
In the ‘source’ section under ‘shared’ tab add the below code:
[FONT=Courier New]private static class StrDataSource implements DataSource{
private String contents ;
private String mimetype ;
private String name ;
public StringDataSource( String contents
, String mimetype
, String name
) {
this.contents = contents ;
this.mimetype = mimetype ;
this.name = name ;
}
public String getContentType() {
return( mimetype ) ;
}
public String getName() {
return( name ) ;
}
public InputStream getInputStream() {
return( new StringBufferInputStream( contents ) ) ;
}
public OutputStream getOutputStream() throws ServiceException {
throw new ServiceException( "This datasource cannot be written") ;
}
}
[/font]
in the actual code write this:
[FONT=Courier New]
IDataCursor pipelineCursor = pipeline.getCursor();
String host = IDataUtil.getString( pipelineCursor, "smtpHost" );
String port = IDataUtil.getString( pipelineCursor, "smtpPort" );
String sender = IDataUtil.getString( pipelineCursor, "from" );
String subject = IDataUtil.getString( pipelineCursor, "subject" );
String[] to = IDataUtil.getStringArray(pipelineCursor,"to");
String location = IDataUtil.getString( pipelineCursor, "location" );
String invitationId = IDataUtil.getString( pipelineCursor, "invitationId" );
String start = IDataUtil.getString( pipelineCursor, "startTime" );
String end = IDataUtil.getString( pipelineCursor, "endTime" );
String description = IDataUtil.getString( pipelineCursor, "description" );
try {
Properties prop = new Properties();
// prop.put("mail.smtp.port", port );
prop.put("mail.smtp.host", host );
Session session = Session.getInstance(prop);
session.setDebug(true);
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender));
//message.setFrom(new InternetAddress("[EMAIL="tgunasekhar@gmail.com"]tgunasekhar@gmail.com[/EMAIL]"));
// Set TO
if( to != null && ( to.length > 0 ) ) {
InternetAddress[] address = new InternetAddress[ to.length ] ;
for( int i = 0; i < to.length; i++ ) {
address[ i ] = new InternetAddress( to[ i ] ) ;
}
message.setRecipients( Message.RecipientType.TO, address ) ;
}
// Set subject
message.setSubject(subject);
// Create iCalendar message
StringBuffer messageText = new StringBuffer();
messageText.append("BEGIN:ICALENDAR\n" +
"PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
"ORGANIZER:MAILTO:" ) ;
messageText.append( sender ) ;
messageText.append( "\n" +
"DTSTART:");
messageText.append( start ) ;
messageText.append( "\n" +
"DTEND:" ) ;
messageText.append( end ) ;
messageText.append( "\n" +
"LOCATION:" ) ;
messageText.append( location ) ;
messageText.append( "\n" +
"UID:" ) ;
messageText.append( invitationId ) ;
messageText.append( "\n" +
"DTSTAMP:" ) ;
messageText.append( dateFormat.format( new java.util.Date() ) ) ;
messageText.append( "\n" +
"DESCRIPTION;ALTREP=\"CID:<eventDescriptionHTML>\"" ) ;
messageText.append( "\n" +
"BEGIN:VALARM\n" +
"TRIGGER:-PT15M\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:Reminder\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR"
) ;
Multipart mp = new MimeMultipart();
MimeBodyPart meetingPart = new MimeBodyPart() ;
meetingPart.setDataHandler( new DataHandler( new StrDataSource( messageText.toString(), "text/calendar", "meetingRequest" ) ) ) ;
mp.addBodyPart( meetingPart ) ;
MimeBodyPart descriptionPart = new MimeBodyPart() ;
descriptionPart.setDataHandler( new DataHandler( new StrDataSource( description, "text/html", "eventDescription" ) ) ) ;
//descriptionPart.setContentID( "<eventDescriptionHTML>" ) ;
mp.addBodyPart( descriptionPart ) ;
message.setContent( mp ) ;
// send message
Transport.send(message);
}
catch (MessagingException me)
{
throw new ServiceException(me);
}
catch (Exception ex)
{
throw new ServiceException(ex);
}
[/font]
Declare all the inputs for the service.
I don’t know how many changes are needed. If somebody can put some effort and come up with a solution that would be great.
The other option could be using the Outlook COM component in webMethods (I really didn’t try yet) with WmWin32 package.
Cheers:)
Guna
#webMethods#Flow-and-Java-services#Integration-Server-and-ESB