cancel
Showing results for 
Search instead for 
Did you mean: 

Send email from portal

Former Member
0 Kudos

I have an html page that was designed for our previous portal. Now that we have migrated to EP 7.0 we need to alter the script. The page uses javascript to send the email based on the email URL of the previous portal.


     http://server/portal/pls/portal/myportal.prc_send_email

I was hoping I could just modify this statement to point to EP http://send-email functionality but was wondering if EP 7.0 has a similar ability?

If so could someone point me in the right direction for knowing what to change the statement to.

If not could someone point me in the right direction for creating a jsp page that would send the email?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

OK - I finally resolved this!!)

I added

 SAPJ2EE::library:mail 

to the sharing reference of my portalapp.xml!

Then it works fine with my original code.


//Set Fields for Email based on the Email Bean
String sFromEmail = bEmail.getFromEmail();
String sToEmail = bEmail.getToEmail();
String sSubject = bEmail.getSubject();
String sContent = bEmail.getContent();
		
Properties props = new Properties();
props.put("mail.smtp.host", "hub.my.com");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
		
Message msg = new MimeMessage(session);
		
try
{
     msg.setFrom(new InternetAddress(sFromEmail));
     msg.setRecipient(Message.RecipientType.TO,new InternetAddress(sToEmail));
     msg.setSubject(sSubject);
     msg.setContent(sContent, "text/plain");

     Transport.send(msg);
     return true; 			
}
catch(Exception e)
{
     return false;
}	

Former Member
0 Kudos

OK I have found a WIKI on Sending an email using JSPDynPage but it is very very complex. I need three text fields and a send button. Send button sends the text field data to the user...

Anyone know of some simple sample code out there for acheiving this?

0 Kudos

InitialContext ctx = new InitialContext();

Properties props = new Properties();

props.put("mail.smtp.host","hostname.com");

Session sess = Session.getInstance(props);

// Create new mime message object

Message message = new MimeMessage(sess);

message.setFrom(new InternetAddress("sender at hostname.com"));

message.setRecipient(Message.RecipientType.TO,new InternetAddress("receiver at hostname.com"));

message.setSubject("Subject here");

String content = "Content here";

message.setContent(content,"text/plain");

// Send the message

Transport.send(message);

Former Member
0 Kudos

Thanks Suresh - this was very helpful however I am still stuck trying to figure out how to pass the values the user puts into the text field (subject). I have the form setup and the text fields - where do I post to? What code should go with the button? Does it call the function you gave me or automatically go to doProcessAfterInput - if so I suppose I can fill the bean values under doProcessAfterInput and call the function you have supplied from there? Does doProcessAfterInput automatically see the field values entered by the user?

0 Kudos

Hi,

use your beans and store the user inputs.

you need to include the code in the doProcessAfterInput.

Please follow the below link which can guide you

http://help.sap.com/saphelp_nw04/helpdata/EN/f5/cfa441cd47a209e10000000a155106/frameset.htm

refer to the

"data Exchange Using a Bean"

section

Thanks,

Suresh Babu Dorai

Former Member
0 Kudos

Thanks Again for your help.

I have gotten the data to pass from the form to the bean and then into the email class. It works fine up until the Email is actually supposed to send and then I get this error:

Caused by: java.lang.NoClassDefFoundError: javax.mail.Address



package com.email;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.bean.emailBean;

public class Email 
{

	public boolean sendEmail(emailBean bEmail) throws Exception
	{
		
		//Set Fields for Email based on the Email Bean
		String sFromEmail = bEmail.getFromEmail();
		String sToEmail = bEmail.getToEmail();
		String sSubject = bEmail.getSubject();
		String sContent = bEmail.getContent();
		String sHost = "hub.mymail.com";
		
		Properties props = new Properties();
		props.put("mail.transport.protocol", "smtp");
		props.put("mail.smtp.host", sHost);
		Session session = Session.getDefaultInstance(props, null);
		session.setDebug(false);

		//Create new mime message object
		Message msg = new MimeMessage(session);

		try
		{
			msg.setFrom(new InternetAddress(sFromEmail));
			msg.setRecipient(Message.RecipientType.TO,(new InternetAddress(sToEmail)));
			msg.setSubject(sSubject);
			msg.setContent(sContent, "text/plain");

			Transport.send(msg);

			return true;
		}
		catch(Exception e)
		{
			return false;
		}			
	}
}

I have included the mail.jar file as a UsedDC in the project - so it compiles fine and I cannot figure out why it cannot see the classes associated to the file. Any suggestions as to what might be going wrong here? Perhaps I am missing a reference for Portal.xml? (although the sample JSP Email Part 2 doesn't include anything I don't have so I doubt that it is but...)

Former Member
0 Kudos

If you are getting this error at runtime then the application isnt locating the mail.jar file at runtime, have you bundled the application along with the jar files?

Thanks,

GLM

Former Member
0 Kudos

Yes - I can see the mail.jar file in the used DCs and I have tried checking the Dependency Types Build Time and Run Time (I have also tried without Run Time checked but get the same error). I also see mail.jar in the Java Build Path Libraries.

I would think that the build would fail if it couldn't see the file as I have several imports related to it.