I am working on Oracle MAF app and using Java mail API for sending outlook meeting requests. I can successfully send mail from java command-line, but when trying same using Mobile app, the code doesn't go after where creating "MimeMessage" class object.
MimeMessage message = new MimeMessage(mailSession);
printStackTrace() shows this exception:
06-09 10:54:43.146: D/JVM(16075): [SEVERE - oracle.adfmf.framework - Utility - invoke] InvocationTargetException Error: ERROR [oracle.adfmf.framework.exception.AdfException] - Error invoking method 'sendMail' in 'class beans.UtilBean'
06-09 12:14:07.466: I/System.out(3760): [SEVERE - oracle.adfmf.framework - adf.mf.internal - logError] Request: {"classname":"oracle.adfmf.framework.api.Model","method":"processBatchRequests","params":[false,[{"classname":"oracle.adfmf.framework.api.Model","method":"evaluateMethodExpression","params":["#{UtilBean.sendMail}",[{".type":"oracle.adfmf.amx.event.ActionEvent"}],"void",["oracle.adfmf.amx.event.ActionEvent"]]}]]} exception: {"message":"Error invoking method 'sendMail' in 'class beans.UtilBean'",".exception":true,"severity":"ERROR",".type":"oracle.adfmf.framework.exception.AdfException"}
Full source code of my class is here:
package beans;
import java.util.Properties;
import javax.mail.Authenticator;
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;
import oracle.adfmf.amx.event.ActionEvent;
public class Email {
private static final String SMTP_HOST_NAME = "mail_host_name";
private static final String SMTP_AUTH_USER = "smtp_user_id";
private static final String SMTP_AUTH_PWD = "smtp_auth_pass";
private static final String SMTP_AUTH_PORT = "smtp_port";
private static final String MAIL_FROM_ADDRESS = "from_addr";
private static final String RECEIPENT_1 = "receipent_1_addr";
private static final String RECEIPENT_2 = "receipent_2_addr";
public void sendEmail(ActionEvent actionEvent) {
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", SMTP_AUTH_PORT);
Authenticator auth = new SMTPAuthenticator();
//Get the session object
Session mailSession = Session.getDefaultInstance(props, auth);
//compose message
try {
System.out.print("CALLED0"); //I can see this in Logcat Logs
MimeMessage message = new MimeMessage(mailSession); // Program stuck here
System.out.print("CALLED1");//I can not see this in Logcat Logs
message.addHeaderLine("method=REQUEST");
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=vevent");
message.setFrom(new InternetAddress(MAIL_FROM_ADDRESS));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(RECEIPENT_1));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(RECEIPENT_2));
message.setSubject("Outlook Meeting Request Using JavaMail");
StringBuffer sb = new StringBuffer();
StringBuffer buffer =
sb.append("BEGIN:VCALENDAR\n" + "PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" + "METHOD:REQUEST\n" + "BEGIN:VEVENT\n" +
"ATTENDEE;CN=\"Attendee1\";ROLE=REQ-PARTICIPANT;MAILTO:[email protected]\n" +
"ATTENDEE;CN=\"Attendee2\";ROLE=OPT-PARTICIPANT;MAILTO:[email protected]\n" +
"ORGANIZER:MAILTO:[email protected]\n" + "DTSTART:20050406T073000Z\n" +
"DTEND:20050406T080000Z\n" + "LOCATION:conf\n" + "TRANSP:OPAQUE\n" + "SEQUENCE:0\n" +
"UID:040000008200E00074C5B7101A82E00800000000A0A742E5073AC5010000000000000000100\n" +
" 0000029606C073D82204AB6C77ACE6BC2FBE2\n" + "DTSTAMP:20050405T122004Z\n" +
"CATEGORIES:Meeting\n" + "DESCRIPTION:What are you doing?\n\n" + "SUMMARY:How are you?\n" +
"PRIORITY:5\n" + "CLASS:PUBLIC\n" + "BEGIN:VALARM\n" + "TRIGGER:PT1440M\n" +
"ACTION:DISPLAY\n" + "DESCRIPTION:Reminder\n" + "END:VALARM\n" + "END:VEVENT\n" +
"END:VCALENDAR\n");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
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);
System.out.println("message sent successfully");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}
}
In Email class I added print statement before and after where creating "MimeMessage" class object, I am able to see first print in logcat but not second.
Deploying java project on Web logic server as a web service (as a .war package) worked for me.