cancel
Showing results for 
Search instead for 
Did you mean: 

Send Email in webdynpro for java

Former Member
0 Kudos

Hi friends,

I am having a scenario in my application to send a mail . i am following the below code .I am not facing any errors but mail is not sent. even my SMTP host name also correct.

try{

InitialContext ctx = new InitialContext();

Properties props = new Properties();

props.put("mail.smtp.host","172.16.22.14");

Session sess = Session.getInstance(props);

Message message = new MimeMessage(sess);

message.setFrom(new InternetAddress(wdContext.currentContextElement().getCreatedBy()+"@accenture.com"));

String recepient = "ratnakar.r.alwala@accenture.com";

message.setRecipient(Message.RecipientType.TO, new InternetAddress(recepient));

String subject = wdContext.currentTasksBeanElement().getType();

message.setSubject(subject);

String content = wdContext.currentTasksBeanElement().getDescription();

message.setContent(content,"text/plain");

// Send the message

Transport.send(message);

msgMgr.reportSuccess(" Mail has been sent successfully");

}catch(Exception e)

{

msgMgr.reportSuccess(" Error occured in Email Sending"+e.getMessage());

}

could any body please look in to this and reply ASAP

Thanks and regards

Ratnakar reddy

Accepted Solutions (1)

Accepted Solutions (1)

former_member751941
Active Contributor
0 Kudos

Hi Ratnakar,

Check the value of “wdContext.currentContextElement ().getCreatedBy()”

wdComponentAPI.getMessageManager().reportSuccess("Created By : "+ wdContext.currentContextElement().getCreatedBy());

what value you are getting is there any email id exists using that name.

Regards,

Mithu

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

logon on the Visual Admin and check in the <b>Java Mail</b> Service if your SMTP service is setting up.

After this stop and restart that Service.

Reward points for helpful answers.

Best regards,

Gianluca Barile

Former Member
0 Kudos

Hi,

In addition to the ongoing thread, can somobody answer a simple question of mine?

Assuming the SMTP setup is done in Visual Admin, now coming to the code part, what should the Properties object be populated with?

Should I use

Session session = Session.getInstance(new Properties());

or

Session session = Session.getDefaultInstance(new Properties());

Please note, its an empty Properties object. Do I need to populate it again with the smtp server defined in Visual Admin?

Thanks,

Rajit

Former Member
0 Kudos

Hai ,

Try this one


try
	{
	  Properties props = System.getProperties();
	  props.put("mail.smtp.host","172.16.22.14");
	  Session session = Session.getDefaultInstance(props, null);
	  Message msg = new MimeMessage(session);
	  msg.setFrom(new InternetAddress(wdContext.currentContextElement().getCreatedBy()+"@accenture.com"));
	  msg.setRecipients(Message.RecipientType.TO,
	  InternetAddress.parse("ratnakar.r.alwala@accenture.com", false));
	  msg.setSubject(wdContext.currentTasksBeanElement().getType());
	  msg.setText(wdContext.currentTasksBeanElement().getDescription());
	  msg.setHeader("X-Mailer", "Email");
	  msg.setSentDate(new Date());
	    Transport.send(msg);
	 msgMgr.reportSuccess("Message sent OK.");
	}
	catch (Exception ex)
	{
	  ex.printStackTrace();
	}

Regards,

Naga