You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Doug Tillman <Do...@grainger.com> on 2004/07/01 16:46:51 UTC
Issue Building and Running sandbox-email
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
Re: Issue Building and Running sandbox-email
Posted by Joe Germuska <Jo...@Germuska.com>.
Doug:
I haven't worked with the commons-email stuff lately... but, with
Maven, you shouldn't change project.xml to use different
dependencies; you should instead define Maven properties directing
Maven to use different dependencies. That way you don't worry about
project.xml getting out of sync with CVS, or having merge conflicts
when you update, etc. The best is usually to put these in a
"build.properties" file either in the project directory or in your
home directory, depending on whether you want them shared between
projects or not. (In this case, you might put "override? Y/N"
property (maven.jar.override) in the project/build.properties but the
specifics in ~/build.properties, assuming you want to use the same
javamail/JAF for any projects that depend on them.)
See for details
http://maven.apache.org/reference/user-guide.html#Overriding_Stated_Dependencies
This is totally anecdotal, but I seem to recall having some trouble
with the embedded image stuff when I played around with it -- I
wonder if anyone who has used it successfully can speak up? I didn't
do much with it, which is why I disclaim as "totally anecdotal".
Joe
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn
back; I'll know I'm in the wrong place."
- Carlos Santana
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org