commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Tillman" <Doug.Till...@grainger.com>
Subject Issue Building and Running sandbox-email
Date Thu, 01 Jul 2004 14:46:51 GMT
Hi,
I'm grateful for you taking a stab at making the Javamail API more
usable.  Unfortunately, I ran into a problem building the code with
Maven.  I understand that there are Maven  issues with jar files that
don't follow the standard format with version numbers embedded in them. 
Java's new Javamail 1.3 or so uses mail.jar and activation.jar for the
activation framework.  I renamed these jar files to follow the standard
format and changed the dependencies accordingly in the project.xml.  Now
I get the following trace which isn't much help from what I know.  Any
insights into how to correct this problem would be most appreciate.

java.lang.NullPointerException
        at
org.apache.maven.plugin.PluginCacheManager.setPluginScript(PluginCacheManager.java:281)
        at
org.apache.maven.plugin.PluginManager.loadJellyScript(PluginManager.java:466)
        at
org.apache.maven.MavenSession.loadJellyScript(MavenSession.java:282)
        at
org.apache.maven.project.Project.loadJellyScript(Project.java:1530)
        at
org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:375)
        at
org.apache.maven.MavenSession.attainGoals(MavenSession.java:348)
        at org.apache.maven.cli.App.doMain(App.java:525)
        at org.apache.maven.cli.App.main(App.java:1088)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at com.werken.forehead.Forehead.run(Forehead.java:543)
        at com.werken.forehead.Forehead.main(Forehead.java:573)

I did build the email so that my code would compile.  I'm most eager to
use the feature to embed an image directly into an HTML email rather
than using the <img src> tag.  My code compiles but doesn't send
successfully and doesn't throw an exception.  Does anything in the
simple code below stand out as wrong to you?  Any help appreciated - it
seems so straightforward I don't see what I"m missing.

Again - any help most appreciated.  Regards,

Doug

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.commons.mail.*;
	 
	 public class CommonsHTMLEmailSender {
		 
		 private static boolean debug = true;
		 private Session session;
		 private Properties props;
		 private String textfile;
		 private String htmlfile;
		 
		 public CommonsHTMLEmailSender(){
		 	
			//Set the host smtp address
			props = new Properties();
			props.put("mail.smtp.host",
"corbadev1.ic.grainger.com");
		
			// create some properties and get the default
Session
			Session session =
Session.getDefaultInstance(props, null);
			session.setDebug(debug);
			
		 }
		 
		 public static void main(String[] args) {
			 
			 new
CommonsHTMLEmailSender().buildHTMLMessage();
		 }
		 
		 public void buildHTMLMessage() {
			 
			 try {
			    
			    java.util.ArrayList al = new
java.util.ArrayList();
			    al.add(new
String("tillman.d@grainger.com")); 		    
			    java.net.URL url = new
java.net.URL("file:/c:/temp/javaimage.jpeg"); 
				HtmlEmail he = new HtmlEmail();
				he.setHtmlMsg("<html><img src=cid:"+ 
					he.embed(url,"image.gif")+"></html>");
				he.setSentDate(new java.util.Date());
				he.setHostName("10.128.52.154");
				he.setFrom("doug_tillman@grainger.com");
				he.setSubject("HTML with JPEG
embedded");
				he.setTo(al);
				he.send();			       

			     //postMail(to, from, subject, email);
			     
		 } catch(Exception e){}
		 }
		 
		 
		 public void postMail(String[]to, String from, 
		    String subject, Message msg) 
		 	throws MessagingException {
		
		    // set the from and to address
		    InternetAddress addressFrom = new
InternetAddress(from);
		    msg.setFrom(addressFrom);
		
		    InternetAddress[] addressTo = new
InternetAddress[to.length]; 
		    for (int i = 0; i < to.length; i++)
		    {
			addressTo[i] = new InternetAddress(to[i]);
		    }
		    msg.setRecipients(Message.RecipientType.TO,
addressTo);
		   
		
		    // Optional : You can also set your custom headers
in the Email if you Want
		    msg.addHeader("MyHeaderName", "myHeaderValue");
		
		    // Setting the Subject and Content Type
		    msg.setSubject(subject);
		    Transport.send(msg);
		}
	     
	 }	     

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message