Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-02-2004, 02:06 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
Sending email with java

i found an example that uses these libraries:

import javax.mail.*;
import javax.mail.internet.*;

but they are not recognized. anyone have a link or something to show how to send email using java ( jsp )
__________________
Mike
sde is offline   Reply With Quote
Old 12-02-2004, 03:14 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
ok, well bel helped me out and pointed me to javamail. i can't make this work without an exception. here is my function:
Code:
public static void sendEmail(String to, String from, String subject, String body){
  try{
    Properties props = System.getProperties();

    props.put("mail.smtp.host", "mail.mycompany.com");
    props.put("mail.smtp.port", "25");
    props.put("mail.transport.protocol","smtp");

    Session session = Session.getInstance(props, null);
    Message msg = new MimeMessage(session);

    msg.setFrom(new InternetAddress(from));
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));

    msg.setSubject(subject);
    msg.setText(body);

    msg.setSentDate(new Date());

    Transport.send(msg);
  }catch(Exception e){
    System.out.println("sendEmail()"+ e.toString());
  }
}
and here's my exception:
Quote:
javax.servlet.ServletException: javax/activation/DataSource
org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:800)
org.apache.jsp.pub.processing_jsp._jspService(proc essing_jsp.java:220)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:305)

root cause

java.lang.NoClassDefFoundError: javax/activation/DataSource
com.mycompany.data.Utility.sendEmail(Utility.java: 269)
com.mycompany.data.CustomerUtil.addCustomerWeb(Cus tomerUtil.java:226)
org.apache.jsp.pub.processing_jsp._jspService(proc essing_jsp.java:202)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:305)
is there anything obviously wrong here?
__________________
Mike
sde is offline   Reply With Quote
Old 12-02-2004, 04:33 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
the function works great. when using javamail, you need to include the 'java activation framework' ( jaf ) in your project. ( or classpath )
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Developer Position in Kansas City justplaindoug Java 0 10-29-2004 11:52 AM
JAVA Hobbyists Wanted emteam Java 0 08-29-2004 11:27 AM


All times are GMT -8. The time now is 11:43 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting