on 03-10-2010 5:07 PM
Dear Friends,
I am trying to send a mail using the following code but i am facing errors using the Session property .Can u pls help me in sorting this out wether i should import some Jar files or anything else.I am using NWDS 7.0.1 SP3 and JDK 1.5.0_11
I am not able to resolve the type for Session and Mimemessage.Do i have to import any jar files
String host =" "; // Specify the host
// Get the From Address
String from = wdContext.currentContextElement().getFromAddress();
// Get the To Address
String to = wdContext.currentContextElement().getToAddress();
// Initialize Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
*Session session = Session.getDefaultInstance(props, null);*--- //This is where i get an error//
// Create new MimeMessage
MimeMessage message = new MimeMessage(session);-----//This is where i get an error//
try {
// Set the From Address
message.setFrom(new InternetAddress(from));
// Set the To Address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set the Subject
message.setSubject("Test Mail");
// Set the Text
message.setText(wdContext.currentContextElement().getTextMessage());
// Send message
Transport.send(message);
messageMgr.reportSuccess("Mail Sent Successfully");
Pls suggest at the earliest.
Sunny
Edited by: Sunny.SAP on Mar 10, 2010 6:07 PM
Hi,
I am using "mail" and "activation" used DCs.
My code for sending emails is below:
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtpapp");
props.put("mail.smtp.port", "25");
Session session = Session.getInstance(props, null);
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("sender @ domain . com"));
InternetAddress[] address = { new InternetAddress(recipient)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(title);
Multipart mp = new MimeMultipart();
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(body, "WINDOWS-1250");
mp.addBodyPart(mbp1);
msg.setContent(mp);
msg.setSentDate(new Date(System.currentTimeMillis()));
Transport.send(msg);
Regards,
--
Przemysław
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Session error was resolved after i included the external jars in my Proj- activation.jar, mailapi 1.3.3.jar
Another doubt being that is the" host" that you get from the message server host in NWDS-Window-Preferences-SAP J2ee engine-Message ServerHost ??
Thanks
Sunny
Edited by: Sunny.SAP on Mar 11, 2010 10:47 AM
Hi Sunny,
Create Authenticator object and pass in the session object.
Authenticator auth = new Auth(); BEFORE your session object!
Then create JAVA class and put in your package folder. Like
package com.email;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class Auth extends Authenticator {
public PasswordAuthentication getPasswordAuthentication()
{
String username = "";
String password = "";
return new PasswordAuthentication(username,password);
}
}
Hope this will help you.
Regards,
Arun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
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.