on 02-23-2007 2:44 PM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
i tried to this code but no use
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
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.