on 03-28-2007 2:27 PM
Hi SDN's,
I m trying to send mail using webdynpro application. i donno whats wrong in dat code. its not throughing any error while deploying. but after getting executed its thorughing sme runtime error.
i m sending da code what i hav written, plz find out whats wrong in this. n where i need to change da content.
plz tell me
public void wdDoInit()
{
//@@begin wdDoInit()
wdContext.currentMailElement().setTo("amar@com");
wdContext.createMailElement().setFrom("amarnath.venkat@in.sealconsult.com");
wdContext.currentMailElement().setSubject("Hi how r u");
wdContext.currentMailElement().setMessage("This is my first mail");
//@@end
}
public void onActionSendEmail(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionSendEmail(ServerEvent)
Properties props = new Properties();
String host = "mail.in.sealconsult.com";
props.put("mail.smtp.host",host);
Session session = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(session);
Address toAddress = new InternetAddress();
Address fromAddress = new InternetAddress();
Address subjectAddress = new InternetAddress();
Address bodyAddress = new InternetAddress();
try{
MimeMultipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
if(! wdContext.currentMailElement().getFrom().equals(""))
{
fromAddress = new InternetAddress(wdContext.currentMailElement().getFrom());
message.setFrom(fromAddress);
}
if (! wdContext.currentMailElement().getTo().equals(""))
{
toAddress = new InternetAddress(wdContext.currentMailElement(). getTo());
message.setRecipient(Message.RecipientType.TO, toAddress);
}
if (! wdContext.currentMailElement().getSubject().equals("") )
{
message.setSubject(wdContext.currentMailElement().getSubject());
}
if (! wdContext.currentMailElement().getMessage().equals(""))
{
messageBodyPart.setText(wdContext.currentMailElement().getMessage());
}
multipart.addBodyPart(messageBodyPart);
messageBodyPart.setHeader("Content-Type","application/pdf");
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();
}
I blive i m placing so much of code over here, even though plz tell me da solution
Thanks in advance
Hi Amar,
Make sure the following ,
1)You have added the required jar file/s.
2) You have given correct SMTP host address
3)Please chk this code, It seems to address is invalid.
<b>wdContext.currentMailElement().setTo("amar@com");</b>
Regards,
Ramganesan K.
Caritor India Pvt. Ltd.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amar,
The code seems okay but try to debug the session. Use
right after
Session session = Session.getInstance(props,null);
session.setDebug(true);
May be it helps you.
Abhinav Sharma
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
code looks okay, except
try giving IP address instead of host name, and instead of passing NULL authentication in getInstance() , give just properties object,
refer following code if you want to,
Properties props = new Properties();
props.put("mail.smtp.host","<IP address>");
Session sess = Session.getInstance(props);
// Create new mime message object
Message message = new MimeMessage(sess);
message.setFrom(new InternetAddress(emailele.getCtx_va_from()));
String recepient = emailele.getCtx_va_to();
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recepient));
String subject = emailele.getCtx_va_subject();
message.setSubject(subject);
String content = emailele.getCtx_va_content();
message.setContent(content,"application/pdf");
Transport.send(message);
even though it is not getting sent then just try for plaine text, ie.
message.setContent(content,"text/plain"); so if there is any errror we will kno that
hope it helps
regards,
abhijeet
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi abhijeet,
I have been replaced host to IP address, n wat u said those modifications i hav done.
even thoghu it throughing da same error.
in ur code, emailele.getCtx_va_from() what is this. when i used emailele its giving error, after organized imports also,
so, what should i modify
Thanks for ur reply
hi,
create a context hierarchy as below,
ctx_vn_EmailDetails(Context node)
|_ctx_va_contact
ctx_va_subject
ctx_va_from
ctx_va_to
emailele is the element created for context node ctx_vn_EmailDetails.
after this copy the code above in button click and execute
do post the error if occurs
regards,
abhijeet
Message was edited by:
abhijeet mukkawar
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.