cancel
Showing results for 
Search instead for 
Did you mean: 

sending the mail in webdynpro

Former Member
0 Kudos

hi

can i use the java mail api as it is

here in webdynpro

if u have any code regarding this plz send it to me

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Check this

Regards,Anilkumar

Former Member
0 Kudos

hi

i tried to this code but no use

Former Member
0 Kudos

Dear Jagadish,

Try the below code:

public class SendMail

{

public boolean sendMessage(String fromID, String toID, String mailSubject,

String mailBody) {

// Write mail sending logic here

ResourceBundle dbproperties = ResourceBundle.getBundle("name of the properties file");

String from = fromID;

String to = toID;

String subject = mailSubject;

String body = mailBody;

String dbhost = dbproperties.getString("MailServer");

String host = dbhost;

// create some properties and get the default Session

try {

Properties props = new Properties();

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

Session session = Session.getDefaultInstance(props, null);

// create a message

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

InternetAddress[] address = { new InternetAddress(to) };

msg.setRecipients(Message.RecipientType.TO, address);

msg.setSubject(subject);

msg.setSentDate(new Date());

msg.setText(body);

Transport.send(msg);

// System.out.println("Mail has been sent");

// if mail sent , return true, else return false

return true;

} catch (Exception mex) {

System.out.println("Error " + mex);

return false;

}

}// end of sendMail...

}

Incase you are not using the properties file then just mention the details of Host Name and other details.

please let me know the status.

regards

Anil Dichpally

Former Member
0 Kudos

Hi Jagadish,

Refer to the following threads:

Regards,

Jhansi

Former Member
0 Kudos

hi jagadish,

try this:

public boolean send( java.lang.String subject, java.lang.String mess )
  {
    //@@begin send()
	InitialContext ctx = null;
	Address[] address = null;
	Message msg = null;
	Session sess = null;
	
	//compone il messaggio di posta e lo invia...
	  try {
	  	Properties props = new Properties();
	  	props.put("domain","true");
		ctx = new InitialContext(props);
		sess = (Session) ctx.lookup("java:comp/env/mail/MailSession");
		msg = new MimeMessage(sess); 
		//estraggo da WAS l'Email del mittente, ovvero il Portal User (cui corrisp. un account R/3)...
		IWDClientUser utente = WDClientUser.getCurrentUser();
		String senderEmail = utente.getSAPUser().getEmail();
		InternetAddress addressFrom = new InternetAddress(senderEmail);
		msg.setFrom(addressFrom);	
		//estraggo da WAS l'Email dell'Help Desk associato al Portal User loggato...
		String EmailHD = wdContext.nodeT_Property_Out().getElementAt(0).getAttributeAsText("Value_Prop");
		InternetAddress addressTo = new InternetAddress(EmailHD);
		msg.setRecipient(Message.RecipientType.TO, addressTo);
		msg.setSubject(subject);
		if ((mess != null) && (mess.length()>0)) {
			  msg.setContent(mess, "text/plain");
		  } else {
			  msg.setContent("", "text/plain");
		  }
		msg.setSentDate(new GregorianCalendar().getTime());
		msg.saveChanges();
		address = msg.getAllRecipients();
		Transport.send(msg, address);
	  } catch (Exception e) {
		   e.printStackTrace();
		   return false;
	  	}
	  return true;
    //@@end
  }

Regards,

Gianluca Barile

Message was edited by:

Gianluca Barile