on 03-30-2005 5:58 AM
Hi,
I have created a jsp dynpro component which uses java mail api and smtp to send emails. We don't have KM installation and hence we have to use java mail.
The iview works fine in 6.0.7.0.0.Enterprise_Portal_Support_Package_7
but the iview throws NoSuchProvider exception in version
6.0.9.0.0.Enterprise_Portal_Support_Release
Stack trace is as follows:
#1.5#000F20191F04007900000808000023630003F37D54E083F4#1112144550592#com.sap.portal.portal#sap.com/irj#com.sap.portal.portal#msivagur01#1411####5b971e70a0b711d9a7e9000f20191f04#Thread[PRT-Async 5,5,PRT-Async]##0#0#Warning#1#/System/Server#Java###SMTPCurrentException
[EXCEPTION]
{0}#1#javax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:611)
at javax.mail.Session.getTransport(Session.java:541)
at javax.mail.Session.getTransport(Session.java:484)
at javax.mail.Session.getTransport(Session.java:464)
at javax.mail.Session.getTransport(Session.java:519)
at javax.mail.Transport.send0(Transport.java:155)
at javax.mail.Transport.send(Transport.java:81)
I have packaged mail.jar, activation.jar and smtp.jar as part of the par under the lib directory.
I though it could be a version mismatch of the jars and tried removing the jars from the lib directory. But that woudn't work either.
Can you please help?
Thanks,
MS
Prakash,
Here is the code snippet.
try {
InternetAddress[] toAddr =
new InternetAddress[] {
new InternetAddress("to@comp.com")});
while (strTok.hasMoreTokens()) {
String email = strTok.nextToken();
toAddr[i++] = new InternetAddress(email);
}
Properties properties = new Properties();
properties.put("mail.smtp.host", "comp.smtp.com");
MimeMessage msg =
new MimeMessage(Session.getInstance(properties, null));
// Always the send address is same
msg.addFrom(
new InternetAddress[] {
new InternetAddress("from@comp.com")});
msg.setRecipients(
Message.RecipientType.TO,
toAddr);
msg.setSubject(
"Subject");
msg.setText(message);
Transport.send(msg);
} catch (Exception nex) {
logger.warning(nex, "Mail Exception");
}
Please note that the same code is running fine in the older version.
I agree that the error message says that it cannot find the smtp provider, but I have packages the sun's smtp.jar
Any ideas?
Thanks for your time.
Regards,
MS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Prakash,
I used the Default instance for the session and still the same problem.
Do you think it could be jar version mismatch. To test that I removed mail.jar, activation.jar and smtp jar from the application lib, but then the application is failing because it cannot find the classes.
Thanks,
Munish
Hi Munish,
Once you put those libraries in you project then java component uses that instead of going to portal libraries. I don't think it's jar version mismatch. Try pinging your SMTP server from portal server. Is your SMTP server anoynmous.. if not then you have to write a code to logon to your SMTP server.
Message was edited by: Prakash Singh
Hi Munish,
I did some more research and found out that error is due to mismatch of your library in your project to the one on your portal server. Grab the mail.jar & activation.jar from your portal install directory.
it should be in following directory if your portal is SP4.
C:\usr\sap\P48\JC00\j2ee\deploying\lib
Message was edited by: Prakash Singh
Message was edited by: Prakash Singh
Hi Munish and Prakash,
I am facing the same problem what Munish was facing.
I am having the activation.jar and the mail.jar in the par file which I am exporting to the Enterprise Portal.
The javax.mail classes are thus understood by the EP, but when it tries to send the mail using the Transport, it is throwing the 'NoSuchProviderException'.
To give more details, when I get the list of 'Providers' that are available using the API, I don't get the sun's smtp provider
but instead I get the "[TRANSPORT,smtp,com.sap.engine.services.javamail.library.SMTPTransport]" provider, I guess, that's the reason for the exception.
Can you please tell me, how you solved the problem ? Is there a way to register the sun's provider in the EP system where I am facing the problem ?(I did not find the 'jar' from the list of NetWeaverBinaries, which contains the com.sap.engine.services.javamail. Let me know if you have any pointers on this)
Thanks in advance,
Vijay
Hi MS,
The error tells me that somehow you the servlet cannot get to your smtp server. Is your SMTP server anoymous? can you post your code. You can use the DynPage code that sends email and it works for me. You only need to put activation.jar and mail.jar in you lib folder.
package co.ust.feedback;
import java.util.GregorianCalendar;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.sapportals.htmlb.enum.ButtonDesign;
import com.sapportals.htmlb.enum.DataType;
import com.sapportals.htmlb.enum.GroupDesign;
import com.sapportals.htmlb.enum.TextViewDesign;
import com.sapportals.htmlb.page.DynPage;
import com.sapportals.htmlb.event.Event;
import com.sapportals.htmlb.page.PageException;
import com.sapportals.htmlb.*;
import com.sapportals.portal.htmlb.page.PageProcessorComponent;
public class feedback extends PageProcessorComponent {
public DynPage getPage() {
return new MyDynPage();
}
public class MyDynPage extends DynPage {
private final static int INITIAL_STATE = 0;
private final static int SENTMAIL_STATE = 1;
private final static int ERROR_STATE = 2;
private final static int NO_FEEDBACK = 3;
private int state = INITIAL_STATE;
private String email_from;
private String txtdescr;
private String error_messg;
/**
* Things to initialice once per session.
*/
public void doInitialization() throws PageException {
state = INITIAL_STATE;
}
/**
* Will be called if forms with data was send.
*/
public void doProcessAfterInput() throws PageException {
InputField myInputField = (InputField) getComponentByName("EMAIL_ADDR");
HtmlEdit txtdescr = (HtmlEdit)getComponentByName("Edit_Text");
if (myInputField != null) {
this.email_from = myInputField.getValueAsDataType().toString();
}
if (txtdescr != null) {
this.txtdescr = txtdescr.getText();
}
}
/**
* Will always be called before output. So this is the method in which
* the components will be placed and set.
*/
public void doProcessBeforeOutput() throws PageException {
System.out.println("doProcessBeforeOutput");
Button myButton;
Form myForm = getForm();
Group myGroup = new Group();
myGroup.setWidth("370");
myGroup.setTitle("Suggestions or Feedback");
myGroup.setDesign(GroupDesign.SAPCOLOR);
myForm.addComponent(myGroup);
GridLayout gl = new GridLayout();
myGroup.addComponent(gl);
switch (state) {
case INITIAL_STATE:
GridLayout g2 = new GridLayout();
g2.setCellSpacing(4);
TextView txtdescr = new TextView("We want to make your opinion count so please provide any relevant suggestions or feedback you may have. We will review all feedback in an effort to provide you with better services and improve the overall portal. Enter your comments below and click send.");
txtdescr.setWrapping(true);
txtdescr.setDesign(TextViewDesign.HEADER3);
g2.addComponent(1, 1, txtdescr);
TextView txtthank = new TextView("Thank you for your feedback!");
txtthank.setDesign(TextViewDesign.HEADER3);
g2.addComponent(2, 1, txtthank);
gl.addComponent(1,1,g2);
GridLayout g3 = new GridLayout();
TextView txtemail = new TextView("Your email address (optional): ");
txtemail.setDesign(TextViewDesign.HEADER3);
g3.addComponent(6, 1, txtemail);
InputField email_addr = new InputField("EMAIL_ADDR");
email_addr.setType(DataType.STRING);
email_addr.setSize(40);
email_addr.setMaxlength(50);
g3.addComponent(6, 2, email_addr);
gl.addComponent(2,1,g3);
HtmlEdit he = new HtmlEdit("Edit_Text");
he.setHeight("300");
he.setWidth("405");
he.setDoPreview(false);
he.setDoPrint(false);
he.setDoCutCopyPaste(true);
he.setDoList(true);
he.setDoAlign(true);
he.setDoInOutdent(true);
he.setDoImage(false);
he.setDoLink(true);
he.setDoLinkKM(false);
gl.addComponent(5, 1, he);
myButton = new Button("submit", "Send");
myButton.setOnClick("onSubmit");
myButton.setWidth("100px");
myButton.setDesign(ButtonDesign.EMPHASIZED );
gl.addComponent(7, 1, myButton);
break;
case SENTMAIL_STATE:
TextView label = new TextView("Thank you for your feedback.");
gl.addComponent(1, 1, label);
break;
case NO_FEEDBACK:
TextView lblnotext = new TextView("Please enter some feedback.");
lblnotext.setDesign(TextViewDesign.HEADER3);
gl.addComponent(1, 1, lblnotext);
myButton = new Button("submit", "Back");
myButton.setOnClick("onBack");
myButton.setWidth("100px");
myButton.setDesign(ButtonDesign.EMPHASIZED );
gl.addComponent(2, 1, myButton);
state = INITIAL_STATE;
break;
case ERROR_STATE:
TextView errortext = new TextView(error_messg);
errortext.setDesign(TextViewDesign.HEADER3);
errortext.setWrapping(true);
gl.addComponent(1, 1, errortext);
myButton = new Button("submit", "Try Again");
myButton.setOnClick("onBack");
myButton.setWidth("100px");
myButton.setDesign(ButtonDesign.EMPHASIZED );
gl.setCellSpacing(4);
gl.addComponent(2, 1, myButton);
state = INITIAL_STATE;
}
}
public void onSubmit(Event event) throws PageException {
if (txtdescr.equals("")) {
state = NO_FEEDBACK;
}
else {
send_mail();
if ( state != ERROR_STATE )
{ state = SENTMAIL_STATE; }
}
}
public void onBack(Event event) throws PageException {
}
public void send_mail ()
{
try{
// Set the host smtp address
Properties props = new Properties();
//put the smtp server here
props.put("mail.smtp.host", "xxxx.com");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props,null);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom;
if (email_from.equals("") )
{
addressFrom = new InternetAddress("anonymous");
}
else
{
addressFrom = new InternetAddress(email_from);
}
msg.setFrom(addressFrom);
InternetAddress addressTo = new InternetAddress("xxx@aol.com");
msg.setRecipient(Message.RecipientType.TO,addressTo);
msg.setSubject("Portal Feedback");
msg.setContent(txtdescr, "text/html");
msg.setSentDate(new GregorianCalendar().getTime());
Transport.send(msg);
} catch (Exception E){
state = ERROR_STATE;
error_messg = "Error sending mail:";
error_messg = error_messg.concat(E.getMessage());
}
}
}
}
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 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.