on 07-31-2006 11:58 AM
Hi,
I am showing data into webdynpro table by accessing database. Now i have to send these data through mail to different persons. How can i do it. I tried it by sending the table elements into excel files but i am facing some problems. can it be done through HTML files??
Please give a solution to it.
Thanks and Regards..
Pankaj Kumar.
Pankaj
I am giving sample code here.
Put this code in an action behind Send Mail button on your iview as an example.
Also add external jar file mail.jar to your web dynpro project to achieve your objective.
if(wdContext.currentContextElement().getTest()== null)
{
IWDWindowInfo windowInfo1 = wdComponentAPI.getComponentInfo().findInWindows("EnterText");
IWDWindow window1 =wdComponentAPI.getWindowManager().createWindow(windowInfo1,true);
window1.open();
window1.setWindowPosition(300,300);
wdContext.currentContextElement().setEmptyText(window1);
} else
{
Properties props = new Properties();
String host = "XXX.XXX.X.X"; /*ip address of mail server */
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth","false");
// auth = new AuthenticationBean();
Session session = Session.getInstance(props, null);
MimeMessage message = new MimeMessage (
Session.getInstance ( props, null ) );
Address toAddress = new InternetAddress();
Address fromAddress = new InternetAddress();
Address ccAddress = new InternetAddress();
Address bccAddress = new InternetAddress();
//new window code
IWDWindowInfo windowInfo = wdComponentAPI.getComponentInfo().findInWindows("SuccessWindow");
IWDWindow window =wdComponentAPI.getWindowManager().createWindow(windowInfo,true);
window.open();
window.setWindowPosition(300,300);
wdContext.currentContextElement().setSuccess(window);
try
{
MimeMultipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
fromAddress = new InternetAddress(wdContext.currentContextElement().getFromEmail());
message.setFrom(fromAddress);
toAddress = new InternetAddress(wdContext.currentContextElement().getRfcEmail());
wdContext.currentContextElement().setErr(wdContext.currentContextElement().getRfcEmail());
message.setRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(wdContext.currentContextElement().getMycontactDD());
messageBodyPart.setText("Message From :"" " wdThis.wdGetMailAppController().wdGetContext().currentContextElement().getName()"\r\n""\r\n"+wdContext.currentContextElement().getTest());
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
catch (AddressException e)
{
wdComponentAPI.getMessageManager().reportWarning(e. getLocalizedMessage());
e.printStackTrace();
}
catch (SendFailedException e)
{
wdComponentAPI.getMessageManager().reportWarning(e. getLocalizedMessage());
e.printStackTrace();
}
catch (MessagingException e)
{
wdComponentAPI.getMessageManager().reportWarning( e.getLocalizedMessage());
e.printStackTrace();
}
}
Please award points if this helps as this will give you a hint for sending mails.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can do something like this:
From the navigator view in NWDS, create a new file, say "TableData.csv" under src/mimes/Components/<your component>/TableData.csv.
Say your context looks like this:
-Root
--Texts(value node, datasource for your table)
---Msg(value attribute, bound to 1st column of table)
---Msg2(value attribute, bound to 2nd column of table)
In the event handler for send button, use a code like this:
String path = null;
try {
path = WDURLGenerator.getResourcePath(
wdComponentAPI.getDeployableObjectPart(),
"TableData.csv");
} catch (WDAliasResolvingException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
FileWriter f = new FileWriter(path);
BufferedWriter b = new BufferedWriter(f);
IWDNode tableNode = wdContext.nodeTexts();
for(int i = 0; i < tableNode.size(); i++){
IWDNodeElement currElem = tableNode.getElementAt(i);
b.write(currElem.getAttributeValue("Msg").toString());
b.write(",");
b.write(currElem.getAttributeValue("Msg2").toString());
b.write(",");
b.newLine();
}
b.close();
} catch (IOException e) {
// TODO Auto-generated catch block
wdComponentAPI.getMessageManager().reportException(e.getMessage(),true);
}
Now you can attach this "TableData.csv" file to the mail.
Regards,
Satyajit.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
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.