How to send a email meeting notification through java.

Hi Experts,

Is it possible to send Meeting Invites to email recipients, using Lotus Notes like mail client. The invite needs to be generated completely from within out java web application code.

Thanks
S
bcisystemsAsked:
Who is Participating?
 
for_yanCommented:

Frankly, already don't remember the details, but this code worked
for me for several years, sending invitations in the morning
about event at 2:00 pm every Mon-Thurs; recipients used  Outlook 2003

It was rather painful, and still not fully satisfied me in a sense
of reminders to recipients.

Still, if nothing  "more official" and format independent showed up by now, and if your
users are using Outlook, maybe you want to look at this code and format of the invitation in it

I guess RandomArray class is not necerssary - I wanted to randomize order of recipients each day

import java.util.Properties;
import java.util.Date;
import java.util.Vector;
import javax.mail.BodyPart;
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;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.text.SimpleDateFormat;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;

public class Email
{
public Email()
{
}

/**
*
* @param args
*/
public static void main(String[] args)
{
try
{
Email email = new Email();
email.send();
}
catch (Exception e)
{
e.printStackTrace();
}

}

public void send() throws Exception {

try {



String from = "one.guy@company.com";
String to = "another.guy@company.com";
    Vector idStrings = new Vector();
    Vector emails = new Vector();


    Class.forName ("oracle.jdbc.driver.OracleDriver");
      Connection conn =
                    DriverManager.getConnection ("connection_string",
           "user", "password");

    Statement stmt = conn.createStatement();

    ResultSet rs = stmt.executeQuery("select flag, email, id_string from dinner_emails");



    while(rs.next()){
      String  flag = rs.getString(1);
        if(flag.toUpperCase().equals("Y")){
        emails.addElement(rs.getString(2).trim());
        idStrings.addElement(rs.getString(3).trim());
        }
    }

   if(emails.size() < 1) {
       System.out.println("No one to send invite to");
       conn.close();
       System.exit(0);
   }

    int [] orderArray;

    orderArray = RandomArray.getRandomArray(emails.size());

       InternetAddress [] intAdds;
    String [] attStrings;
    attStrings = new String[emails.size()];
    intAdds = new InternetAddress[emails.size()];
    String attString = "";

    for(int jj=0; jj<emails.size(); jj++){
        intAdds[jj] = new InternetAddress((String)emails.elementAt(orderArray[jj]));
        attString +=
       "ATTENDEE;CN=\"" +(String)idStrings.elementAt(orderArray[jj]) + "\";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:"+
               (String)emails.elementAt(orderArray[jj]) + "\n";

    }

Properties prop = new Properties();

    java.util.Date now = new java.util.Date();

    SimpleDateFormat ff = new SimpleDateFormat("yyyyMMdd");

    String today = ff.format(now);
    System.out.println(today);
    int year = now.getYear();
    int day = now.getDate();
    int month = now.getMonth();

prop.put("mail.smtp.host", "mailer.company.com");

Session session = Session.getDefaultInstance(prop, null);
// Define message
MimeMessage message = new MimeMessage(session);
message.addHeaderLine("method=REQUEST");
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=VEVENT");


message.setFrom(new InternetAddress(from));
message.addRecipients(Message.RecipientType.TO, intAdds);
message.setSubject("Dinner ordering");

StringBuffer sb = new StringBuffer();

StringBuffer 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" +
attString +
"ORGANIZER:MAILTO:one.guy@company.com\n" +
"DTSTART:" + today +"T210000Z\n" +
"DTEND:" + today + "T210500Z\n" +
"LOCATION:\n" +
"TRANSP:OPAQUE\n" +
"SEQUENCE:0\n" +
"UID:040000008200E00074C5B7101A82E00800000000002FF466CE3AC5010000000000000000100\n" +
" 000004377FE5C37984842BF9440448399EB02\n" +
"DTSTAMP:" + today + "T120102Z\n" +
"CATEGORIES:Meeting\n" +
"SUMMARY:Dinner ordering\n" +
"PRIORITY:5\n" +
"CLASS:PUBLIC\n" +
"BEGIN:VALARM\n" +
"TRIGGER:PT15M\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:Reminder\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR");




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

// Fill the message
messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
messageBodyPart.setHeader("Content-ID","calendar_message");
messageBodyPart.setContent(buffer.toString(), "text/calendar");


// Create a Multipart
Multipart multipart = new MimeMultipart();

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



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

// send message
Transport.send(message);
} catch (MessagingException me) {
me.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

Open in new window



public class RandomArray {

    public static int [] getRandomArray(int n){
        int [] numbers;
        numbers = new int[n];

        for(int jj=0; jj<n; jj++){
            numbers[jj] = -1;
        }
    //    System.out.println(numbers[1]);

        double part = 1.0/n;

        for(int jj=0; jj<100000000; jj++){
            boolean good = false;
            for(int ii=0; ii<n; ii++){
                if(numbers[ii] == -1)good = true;
            }
               if(!good)break;

            double r = Math.random();

            int num = (int) (r/part);

            boolean keep = true;
            for(int ii=0; ii<n; ii++){
                if(numbers[ii] == num)keep = false;

            }
            if(!keep)continue;
             for(int ii=0; ii<n; ii++){
                if(numbers[ii] == -1){numbers[ii] = num;
                 break; }

            }


        }


        return numbers;

    }

    public static void main(String [] args){
         int [] numbers;
        numbers = getRandomArray(1);
        for (int jj=0; jj<1; jj++)System.out.println(numbers[jj]);

    }
}

Open in new window

0
 
colr__Commented:
This has instructions for what you're looking for:

http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
0
 
bcisystemsAuthor Commented:
Colr,

No i am actullay looking for email where in you would go and accept a meeting. So I should be able to send a calendar meeting request.

Thanks
S
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.