on 02-12-2008 1:02 PM
HI,
In my application ,I am triggering a javamail which contain 5 fields in it....
is there by any means ,I can Format the data appearence in the mail message..(like inserting table )
so that that appears in the mail received by the end user,..
Thanx,
Arjun.G
Hi,
change the mime type of the mail to html and make use of table tags available in html.
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Pl go through this example from sun
http://fisheye5.cenqua.com/browse/~raw,r=1.1/glassfish/mail/src/java/demo/sendhtml.java
Regards
Ayyapparaj
Arjun,
Using the JavaMail API requires the JavaMail and JavaBeans Activation Framework JAR files i.e. mail.jar and activation.jar respectively to be in the CLASSPATH of the project.
So download JavaMail 1.4.1 from following [link|http://java.sun.com/products/javamail/downloads/index.html]
and JAF from [here|http://java.sun.com/products/javabeans/jaf/downloads/index.html]
Extract the jars I mentioned from the zip files onto your hard-drive somewhere and then add them to your project classpath by doing Right click on your project --> Properties --> Java Build path --> Add External JARs
Check this [Sun Javamail Link|http://java.sun.com/products/javamail/index.jsp] for more details.
Chintan
df
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This is the code i have written for formatting the mail in the java mail...
It does not work out...
Error :
The initial exception that caused the request to fail, was:
java.lang.NoClassDefFoundError: javax/mail/util/ByteArrayDataSource
at com.sap.admin.component.Emp_TrainingNeeds.collect(Emp_TrainingNeeds.java:253)
at com.sap.admin.component.Emp_TrainingNeeds.onActionSaveNExit(Emp_TrainingNeeds.java:380)
at com.sap.admin.component.wdp.InternalEmp_TrainingNeeds.wdInvokeEventHandler(InternalEmp_TrainingNeeds.java:255)
at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
... 27 more
//Java Mail Code Starts from Here
// BufferedWriter wr = new BufferedWriter(new InputStream());
String mess = wdContext.currentNeedBeanElement().getCategory().concat("|").concat(wdContext.currentNeedBeanElement().getCoursegroup().concat("|").concat(wdContext.currentNeedBeanElement().getCoursegroup().concat("|").concat(wdContext.currentNeedBeanElement().getBywhen().toString()).concat("|").concat(wdContext.currentNeedBeanElement().getPriority().concat("|").concat(wdContext.currentNeedBeanElement().getRemarks())
)));
char[] mes= mess.toCharArray();
//InputStream s = new InputStream();
///StringReader s = new StringReader(mess);
InputStream is = new ByteArrayInputStream(mess.getBytes());
BufferedReader in = new BufferedReader(new InputStreamReader(is));
//StringReader in1 = new StringReader(mess);
wdContext.currentContextElement().setTextMessage(mess);
String host ="202.54.xxx.xxx "; // Specify the host
// Get the From Address
// String from = wdContext.currentContextElement().getFromAddress();
String from ="aaaa@yyyy.com";
// Get the To Address
// String to = wdContext.currentContextElement().getToAddress();
String to=" xxxx@yyyy.com";
// Initialize Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
// Create new MimeMessage
MimeMessage message = new MimeMessage(session);
IWDMessageManager messageMgr = wdControllerAPI.getComponent().getMessageManager();
try {// Set the From Address
message.setFrom(new InternetAddress(from));
// Set the To Address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set the Subject
String subj = wdContext.currentNeedBeanElement().getUpdatedby();
String sub = "Training Need of ".concat(subj);
message.setSubject(sub);
collect(in, message);
message.setHeader("X-Mailer","sendhtml");
message.setSentDate(jsqlD);
// Set the Text
message.setText(wdContext.currentContextElement().getTextMessage());
// Send message
Transport.send(message);
messageMgr.reportSuccess("Mail Sent Successfully");
} catch (AddressException e) {
messageMgr.reportException(e.toString(),false);
} catch (MessagingException e) {
messageMgr.reportException(e.toString(),false);
}
public void collect( java.io.BufferedReader in, javax.mail.Message message )
{
//@@begin collect()
try{
String line;
String subject = message.getSubject();
StringBuffer sb = new StringBuffer();
sb.append("<HTML>\n");
sb.append("<HEAD>\n");
sb.append("<TITLE>\n");
sb.append(subject + "\n");
sb.append("</TITLE>\n");
sb.append("</HEAD>\n");
sb.append("<BODY>\n");
sb.append("<H1>" + subject + "</H1>" + "\n");
// String mess = wdContext.currentNeedBeanElement().getCategory().concat("|").concat(wdContext.currentNeedBeanElement().getCoursegroup().concat("|").concat(wdContext.currentNeedBeanElement().getCoursegroup().concat("|").concat(wdContext.currentNeedBeanElement().getBywhen().toString()).concat("|").concat(wdContext.currentNeedBeanElement().getPriority().concat("|").concat(wdContext.currentNeedBeanElement().getRemarks())
// )));
// sb.append(mess);
while (( line = in.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
sb.append("</BODY>\n");
sb.append("</HTML>\n");
message.setDataHandler(new DataHandler(new ByteArrayDataSource(sb.toString(), "text/html")));
}catch(MessagingException e){
e.getMessage();
e.printStackTrace();
}catch(IOException e){
e.getMessage();
e.printStackTrace();
}
//@@end
}
Thxs
Arjun.G
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.