on 2005 Dec 28 10:46 AM
Dear all
Could anyone pl tell me what inputs required in the below mentioned code...
-
public void send_mail ()
{
try{
// Set the host smtp address
Properties props = new Properties();
//put the smtp server here
props.put("mail.smtp.host","105.97.14.72");
// 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("pvpreddy@abccompany.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());
}
}
}
-
when i click the send button ..it says error sending mail:smtp
suggest me
rgds
pradeep
Does your portalapp.xml looks like this?
<property name="PrivateSharingReference" value="SAPJ2EE::library:mail"/>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Detlev
This is my source code....i just copied three jar file into PORTAL-INF/Lib like activation.jar, smtp.jar and mail jar... after that i just creatd par file..deployed into portal...and i have not done anything in portalapp.xml.
-
package Test1;
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("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","105.97.14.72");
// 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("pradeep-pv.reddy@unilever.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());
}
}
}
}
-
What steps do i missed out..to work this.
rgds
pradeep
Message was edited by: Pradeep Reddy
Message was edited by: Pradeep Reddy
Hi Pradeep,
as I have already stated in different other threads, it's a big design mistake to put the Java lib's into your portal application. They are already deployed on the server, and you can just use them via the SharingReference Fausto provided. Anyhow, this is, as said, not the source of your problem.
Next remark: If you are providing code, please use the CODE marker from the SDN editor to make it <i>much</i> more readable.
And: As already told, please submit the exception itself and not only the exception message, as well as the stack trace. This is giving <i>much</i> more information then this bunch of code, for which I really don't have the time to check line by line (and 99% of these lines are uninteresting concerning your problem). <i>In general, if providing code fur support reasons, on SDN or wherever, strip down your code to the absolute minimum!</i> Delete everything on your side which doesn't influence the exception.
So, the question stays, please submit the exception itself and the stack trace.
Best regards
Detlev
Hi Pradeep,
I took a quick look at your code and i saw that your using global variables for storing the e-mail and the text message. Are you storing them in a bean or something like that?
If not when you click on the button the values that you stored will be lost.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pradeep,
please submit the error itself, even better: the stack trace, instead of only the error's message.
Thanks in advance
Detlev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
8 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.