Error Compiling With java.mail.Session class
Hi,
The Java compiler issues an error message (below) during compilation of the following line:
Session session = Session.getDefaultInstance( fMailServerConfig, null );
The error message is:
bad class file: c:\j2ee_sdk\lib\j2ee.jar(javax/mail/Session.class)
class file has wrong version 48.0, should be 47.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
javax.mail.Session session = javax.mail.Session.getDefaultInstance( fMailServerConfig, null );
I have tried switching between JDKs by changing the JAVA_HOME environment variable between JDKs 1.3.x to 1.4.x to 1.5.x and also to the JDK installed with the 2005 Q1 J2EE installation that I am using.
Any ideas on how to resolve this problem? And help would be GREATLY appreciated.
Thanks!!!
Stuart Hoffman
in Session session = Session.getDefaultInstance( fMailServerConfig, null ); pass the object of properties class instead of mailServerconfig
now your problem are solved
Similar Messages
-
Only 274 mails are coming when using pop3 with java mail
Only 274 mails are coming from GMAIL when using pop3 with java mail. but there are more than 3000 mails.
I'm not getting the reason, code is given below:
public static void main(String[] args) {
// SUBSTITUTE YOUR ISP's POP3 SERVER HERE!!!
// String host = "pop.bizmail.yahoo.com";
// final String user = "[email protected]";
// final String password = "xxx";
String host = "pop.gmail.com";
final String user = "gauravjlj";
final String password = "xxx";
String subjectSubstringToSearch = "Test E-Mail through Java";
try {
Properties prop = new Properties();
prop.setProperty("mail.pop3.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
prop.setProperty("mail.pop3.socketFactory.fallback", "false");
prop.setProperty("mail.pop3.port", "995");
prop.setProperty("mail.pop3.socketFactory.port", "995");
prop.put("mail.pop3.host", host);
prop.put("mail.store.protocol", "pop3");
Session session = Session.getDefaultInstance(prop);
Store store = session.getStore();
System.out.println("your ID is : "+ user);
System.out.println("Connecting...");
store.connect(host, user, password);
System.out.println("Connected...");
// Get "INBOX"
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_ONLY);
int count = fldr.getMessageCount();
System.out.println(count + " total messages");
// Message numebers start at 1
for(int i = 1; i <= count; i++) {
// Get a message by its sequence number
Message m = fldr.getMessage(i);
// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);
// Search for e-mails by some subject substring
String pattern = subjectSubstringToSearch;
SubjectTerm st = new SubjectTerm(pattern);
// Get some message references
Message [] found = fldr.search(st);
System.out.println(found.length +
" messages matched Subject pattern \"" +
pattern + "\"");
for (int i = 0; i < found.length; i++) {
Message m = found;
// Get some headers
Date date = m.getSentDate();
Address [] from = m.getFrom();
String subj = m.getSubject();
String mimeType = m.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);
Object o = m.getContent();
if (o instanceof String) {
System.out.println("**This is a String Message**");
System.out.println((String)o);
else if (o instanceof Multipart) {
System.out.print("**This is a Multipart Message. ");
Multipart mp = (Multipart)o;
int count3 = mp.getCount();
System.out.println("It has " + count3 +
" BodyParts in it**");
for (int j = 0; j < count3; j++) {
// Part are numbered starting at 0
BodyPart b = mp.getBodyPart(j);
String mimeType2 = b.getContentType();
System.out.println( "BodyPart " + (j + 1) +
" is of MimeType " + mimeType);
Object o2 = b.getContent();
if (o2 instanceof String) {
System.out.println("**This is a String BodyPart**");
System.out.println((String)o2);
else if (o2 instanceof Multipart) {
System.out.print(
"**This BodyPart is a nested Multipart. ");
Multipart mp2 = (Multipart)o2;
int count2 = mp2.getCount();
System.out.println("It has " + count2 +
"further BodyParts in it**");
else if (o2 instanceof InputStream) {
System.out.println(
"**This is an InputStream BodyPart**");
} //End of for
else if (o instanceof InputStream) {
System.out.println("**This is an InputStream message**");
InputStream is = (InputStream)o;
// Assumes character content (not binary images)
int c;
while ((c = is.read()) != -1) {
System.out.write(c);
// Uncomment to set "delete" flag on the message
//m.setFlag(Flags.Flag.DELETED,true);
} //End of for
// "true" actually deletes flagged messages from folder
fldr.close(true);
store.close();
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
catch (IOException ioex) {
ioex.printStackTrace();
Please tell me.
ThanksIs it possible that GMail only allows access to untagged emails via POP3? Or only to emails from the last x days?
POP3 is the older email retrieval protocol (IMAP4 is the more current one) and only has very limited support for folders (or anything but a single inbox, really). It's quite common that POP3 only allows access to a subset of all emails stored by a provider. -
hi all
ive installed jdk1.4.1 from jdk1.3 .
When i try to compile a java file i get this error.
Error: invalid file 'java/lang/Object.class' (wrong version: 48, expected 45)
anyone has any idea abt this.
im stuck :( pls help.
thanks
JanDid you uninstall 1.3 completely? Completely in the sense both jdk and jre.
You may get this error if you use javac of one version and the rt.jar of another version.
Sudha -
Javax.mail.Session Class Cast Exception
I'm tryin' to send a mail via JNDI Java Mail Session, but when i get the look up Object, ClassCastException are thrown
When i take the o.getClass().getName() is equal to the cast class that i use. I don't know what to do.
Source --->
Object o;
context = new InitialContext();
o = context.lookup("java:comp/env/mail/mysession");
System.out.println(o.getClass().getName());
return (javax.mail.Session) o; // Exception here!DUH!
I'm using incorrect mail.jar version...
:') -
How to use a progress bar with java mail?
Hi, i'm new here.
I want if someone can recommend me how to show a progress bar with java mail.
Because, i send a message but the screen freeze, and the progress bar never appear, after the send progress finish.
ThanksSo why would the code we post be any different than the code in the tutorial? Why do you think our code would be easier to understand? The tutorial contains explanations about the code.
Did you download the code and execute it? Did it work? Then customize the code to suit your situation. We can't give you the code because we don't know exactly what you are attempting to do. We don't know how you have changed to demo code so that it no longer works. Its up to you to compare your code with the demo code to see what the difference is. -
How can I enforce the communication on TLS 1.2 with Java Mail API?
I try to set TLSv1.2 is SSLContext but the communication always takes place on TLSv1.
Please suggest.Are you setting a new default SSLContext?
By default, JavaMail will use the default SSLSocketFactory, which (I believe) by default will use the default SSLContext.
You can also set the property mail.<protocol>.ssl.protocols to the protocol you want to be used,
which will be passed to the SSLSocket.setEnabledProtocols method. -
Hi
We have a requirement to create a custom e mail. For the same I am trying to use Java Mail API.I am facing an issue with the following code:
session session1 = session.getInstance(properties, null);
System gives an error Sourced file: inline evaluation of: ``Properties props = new Properties(); session session1 = session.getInstance(prop . . . '' : Typed variable declaration : Class: session not found in namespace
Is there some specific API i need to import for session class. Kindly suggest.
Regards
ShobhaHi Shobha,
I was also facing the same issue from last couple of weeks and just now i have achieved the working functionality.
Please find below working code and replace values as per your serveru2019s configuration.
import com.sap.odp.api.util.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.File;
import java.net.*;
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to =<email address>;
String from =<email address>;
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = <smtp host name>;
String user = <smtp user name>;
// Create properties, get Session
// Properties props = new Properties();
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", host);
props.put("mail.debug", "false");
props.put("mail.smtp.auth", "false");
props.put("mail.user",user);
props.put("mail.from",from);
Session d_session = Session.getInstance(props,null);//Authenticator object need to be set
Message msg = new MimeMessage(d_session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());
msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.");
Transport.send(msg);
Deepak!!! -
Error of using Java Mail in Web Start
Hi,
I got a problem when using Java Mail to send email. My apps is a stand alone and no problem when it was deployed normally. When I used the Web Start to deploy it, the following error was caught when I tried to send email:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary="----=_Part_0_2824645.1032281188963"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:851)
at javax.activation.DataHandler.writeTo(DataHandler.java:305)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1089)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1527)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:321)
at javax.mail.Transport.send0(Transport.java:164)
at javax.mail.Transport.send(Transport.java:81)
at com.mailcom.client.util.EMail.sendMail(EMail.java:180)
Here is the source code:
public class EMail {
public static void sendMail(String host,
String sender,
String recipient,
String subject,
String content,
Vector fileNames) throws MessagingException {
Properties props = new Properties();
props.put("mail.smtp.host",host);
Session session = Session.getDefaultInstance(props,null);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(sender));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient,false));
msg.setSubject(subject);
Multipart mp = new MimeMultipart();
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(content);
mp.addBodyPart(mbp1);
// attach the file to the message
if(fileNames != null && fileNames.size() != 0) {
FileDataSource fds = null;
for(int i = 0; i < fileNames.size(); i++ ) {
String currentFileName = (String)fileNames.elementAt(i);
fds = new FileDataSource(currentFileName);
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
// create the Multipart and its parts to it
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
msg.setHeader("X-Mailer",MAILER);
// set the Date: header
msg.setSentDate(new Date());
// send the message
line 180 Transport.send(msg);Yes. All the third party jar files and our application jar are put on the server side. Here is the JNLP file:
<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for software-->
<jnlp spec="1.0+" codebase="http://www.software.com/apps" href="client.JNLP">
<information>
<title>client application</title>
<vendor> * </vendor>
<homepage href="docs/help.html"/>
<description>Client</description>
<description kind="short">A tool</description>
<icon href="images/logo.jpg"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.3"/>
<jar href="lib/client.jar"/>
<jar href="lib/mail.jar"/>
<jar href="lib/smtp.jar"/>
<jar href="lib/activation.jar"/>
</resources>
<application-desc main-class="com.software.client.MainFrame">
<argument>2226</argument>
<argument>www.software.com</argument>
<argument>5351</argument>
</application>
</jnlp> -
Help with compiling with Java 1.3 in Windows 98
Using JDK 1.3 and Windows 98... here is my problem. If I create a class called EventSite.java and another class called eventsite.java (same name, different cases) and then compile them both...I only see the the first class compiled in the directory (they are both being compiled into the same directory).
i.e. I run 'javac EventSite.java' and when I look in the c:\jdk1_3\bin\ directory I see EventSite.class.
I then run 'javac eventsite.java' and when I look in the same directory I only see EventSite.class. Why???????
Where did eventsite.class go?
Note: both .java files compile without error.
Help please.Yes it is very strange. Both .java files compile clean yet the second one does not seem to create a .class file. If you are using Windows 98 you can do a simple test to see this...
Create a class with a simple method in it.
Save the file as 'Test.java' (capital 'T').
Compile it into a directory (c:\jdk1.3\bin\).
Using Windows Explorer, check the directory and see 'Test.class' exists.
Now go into the code of the same class and just change the name of the class and save as 'test.java' (lower case 't').
Compile it into the same directory (c:\jdk1.3\bin\).
Using Windows Explorer, check the directory and see 'Test.class' still exists, 'test.class' does not.
Note. If you delete 'Test.class' from the directory and then recompile 'test.java', you will then see 'test.class' in the directory.
It's very wierd and it isn't an issue with a particular computer either. I am taking a class in Java currently and everyone in the clas is having this issue...even the professor hasnt seen this before which is why I figured I would ask on here.
Any thoughts???? Thanks -
Having Trouble with Java Mail and Servlets
How can I send and receive mails using Java Mail API and Servlets
You should familiarize yourself with the JavaMail API and the servlet API--this is much too broad a question to properly answer in a forum. The J2EE Tutorial shows how to send a mail message using JavaMail from a session bean, but the technique is similar to what you would use from a servlet:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Resources5.html#wp82097
I'm sure the JavaMail documentation has an example as well.
-Ian Evans -
Cannot figure out what's the problem?
I'm trying to send e-mail via Weblogic Mail Session EJB, the code seems pretty right to me, but it's always is throwing an exception.
For SMTP I'm using personal computer SMTP service (Win XP), smtp.host=my IP address, user=domain name.
--- begin ---
javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.SendFailedException: Invalid Addresses; nested exception is: javax.mail.SendFailedException: 550 5.7.1 Unable to relay for [email protected] at javax.mail.Transport.send0(Transport.java:219)
--- end ---
Does anyone have an idea what's the glitch?This looks like a relay problem. Usually, ISPs have mail locked down so that you cannot send from their SMTP server without being logged in through them. They need to verify that you have an account with them and that you are logged on through that account ... usually done by checking to see if you have done a POP login in the last X number of minutes.
Hope this helps.
Paul -
Hello everyone,
Iam sending mail using java, my mail format consisit of colored text and images,that should be diplsyed to reciever in mail box,my code is working fine reciever gets mail in inbox but problem is when we recieve mail like that images doesnot show up in the mail automaticaly,when i click on show images link in my mail box only then images become visible,i tested my mail in gmail,rediff and yahoo and in all cases i have to mannually click on "show images" link to view images that i sent with my mail,why so? is this due to security reasons in mailbox??? can i write such code that can overcome this problem i.e my images shows directly in anymailbox without clicking on showimages link.
Please help.
Thanks.anie wrote:
can i write such code that can overcome this problem i.e my images shows directly in anymailbox without clicking on showimages link.No. That's a security function of the browser, and not something you can control.
On another note, please refrain from posting unnecessary, excessive punctuation. It only clutters up your message, which isn't a good thing. Thanks!
~ -
Can I FAX with JAVA MAIL??
Any body can help me with some key code to fax with my Java mail?? What are the other requirements apart from JAVA MAIL API???
Thanking you
AchintyaHello! Achintya, what I know is you need to hv a service provider to convert yr e-mail into fax format & send to the destination.
iSam
[email protected] -
How to send image as a part of body with java mail
How to send image (.GIF) file in mail body & not as an attachement using java mail API
You need to create a multipart/related message.
You'll probably find examples in this forum. -
How to compile a java file to class with class
There is a java file.
And i want to compile it with class, not javac command.
so i can catch the compile errors.
how to do it?
special thanks.http://java.sun.com/developer/JDCTechTips/2003/tt0722.html#2
Maybe you are looking for
-
How would I create a simple script that does these specific things?
I am trying to create a script that does these few simple task but I can't seem to compile all the cmdlets together into one. I can pick one task out and have a command for it but I want one script to do it all. Here are the tasks I need it to do. st
-
I would like to upgrade my old Pages 3.0.3 to a newer version. When I went to the app store I got a message that says "Pages 3.0.3 is already installed and was not purchased from the Mac App Store. Do you want to buy Pages 4.3?" I thought I was jus
-
Sub-Organization's Network control Policy used by a vNIC Template causes Warning
Hi, using UCSM 1.4.(1i) if a Network Control Policy defined in a Sub-Origaniziation is used by a vNIC Template the following warning shows up: * Description: ** Policy reference nwCtrlPolicyName does not resolve to named policy. * ID: 792882 * Cause:
-
I want to install one more airport in my home to expand coverage. Will the two units still function independently?
-
WD Caviar Black WD6401AALS - hard drive - 640 GB - SATA-300
I currently use an external hard drive to store my music ec on and have noticed that it is getting more and more sluggish and that the internal hard drive seems considerably faster. For this reason I'm looking at installing an additional internal har