1

Below is one of the targets that runs after the completion of tests, buil.xml(pass or fail). This target is failing and giving error "java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage". So I expanded the mail.1.4.jar file and saw this class was there. So next I checked that this jar was there in my setclasspath target or not, and it was there. Third thing I checked that mail.1.4.jar was included in ant's path or not and it was there. Now I am not able to understand why I am getting this error.

<target name="sendmail">
    <mail from="[myname@company.com]"
    subject="Test Email" mailhost="smpt.gmail.com" 
    user="myusername" password="mypassword" message="This is a test email">
        <to name="receivers name" address="[receiver@gmail.com]" />
    </mail>
</target>
Himanshu Bhardwaj
  • 4,038
  • 3
  • 17
  • 36
Pushpraj Singh
  • 67
  • 2
  • 3
  • 10

4 Answers4

1

If Ant gives the “java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage” error, it means there is a jar missing.

Go to the findjar website: http://www.findjar.com/, and find the corresponding jar by searching "javax.mail.internet.MimeMessage". You'll find it's mail.jar.

Then download the jar file from the central Maven repository: https://mvnrepository.com/artifact/javax.mail/mail, for example, version mail-1.4.7.jar, and put it in your Ant lib directory: ${ANT_HOME}/lib

That should work.

Yuci
  • 27,235
  • 10
  • 114
  • 113
0

Add mail.jar in the classpath and related transitive dependencies.

Ok try the following, firstly in your ant installation, ${ANT_HOME}/lib check if the following jar is present, ant-javamail, if NOT:

You can find the following here: http://mvnrepository.com/artifact/org.apache.ant/ant-javamail

Pick the correct one according to your ant version.

Copy this jar in the lib directory of ant. And try to rerun the task.

Let know if it resolves.

Command to run

ant -f %ANT_HOME%/fetch.xml -Ddest=user -Dm2.url=repo1.maven.org/maven2
Himanshu Bhardwaj
  • 4,038
  • 3
  • 17
  • 36
  • Tried, same error. There is another way using **ant -logger org.apache.tools.ant.listener.MailLogger**, could you please , guide me how to use it. – Pushpraj Singh Apr 15 '13 at 13:07
  • I will check and get back also post a minimal build.xml so we can teston same – Himanshu Bhardwaj Apr 15 '13 at 13:12
  • ant-javamail wasn't there , so I downloaded its 1.8.2 version and added it. I went to Windows>>Preferenes>> Ant >> runtime>> global entries and clicked add jar (via eclipse IDE).Now error is changed a little. Now it says : – Pushpraj Singh Apr 16 '13 at 05:15
  • sendmail: [mail] Failed to send email: javax.mail.internet.MimeMessage BUILD FAILED /home/quov/Desktop/myproject/build.xml:157: java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage – Pushpraj Singh Apr 16 '13 at 06:56
  • Make sure, ANY_HOME is correctly set, then execute the following command: see the updated answer – Himanshu Bhardwaj Apr 16 '13 at 07:04
0

I got the similar error from the 1st thread before. You probably want to download both mail.jar and activation.jar to be located under your ant library folder and when you executed the build, make sure you use "ant -lib" with the path to your lib folder.

juniorb
  • 81
  • 1
  • 4
0

If you're using Ant via Groovy then you can add the necessary libraries via @Grab like so:

@GrabConfig(systemClassLoader=true)
@Grapes([
    @Grab(group='org.apache.ant', module='ant-javamail', version='1.10.7'),
    @Grab(group='com.sun.mail', module='javax.mail', version='1.6.2')
])
rednoah
  • 1,053
  • 14
  • 41