on 03-11-2005 3:37 PM
Hi
we are using DCs in the SAP Netweaver Developer Studio.
We would like to send email using tha JavaMail API. Is this package included in any DC.
Or is there any other API what we can use to send emails?
Best Regards,
Trian
Dearl Yantong Wang or anyone:
Sorry. I also get same problem javax/mail/address , how do i fix the problem?
Please help . Thank you very much.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
take the following code and build a par out it. You need mail.jar and activation.jar. Put mail.jar and activation.jar in PORTAL-INF->lib directory.
com.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();
props.put("mail.smtp.host", "ust.net");
// 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("singhpra@hotmail.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 |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
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.