Random javax.mail.FolderNotFoundException
Hi all,
we have a java application hosted on Win 2000 wich is using javamail api to interact with MS Exchange 2003. Basically is getting folders and iterating trough them.
From time to time we get an error about javax.mail.FolderNotFoundException.
This is happening really randomly and not on the same folder, the ms event viewer doesn't say so much, and the application has basic log4j error with no stack trace, only the getMessage().
My question is, do you know of any existing bug between the three systems wich could cause such error ?
Where do you think I should start to solve the problem ? Network ? Java ?
thanks in advance...
Turn on session debugging and examine the
protocol trace. See the JavaMail FAQ.
Similar Messages
-
Javax.mail.FolderNotFoundException: folder INBOX not found
Hi
I have a simple program called simpleread.java. I have javamail, JAF and javamaildir installed.
Now I know that I am not providing more details and I can post more details. I am very apologetic about this. However I wanted to know if the error I have is kind of general.
So I am posting the following error:
Exception in thread "main" javax.mail.FolderNotFoundException. folder 'INBOX" not found
=======
thanks in advance
I will provide details gladlySounds like a problem with the way javamaildir is configured,
or the way you're using it. You might want to talk to the
javamaildir experts. -
Mail doesn't send - javax.mail.MessagingException: 250
Hello all,
I'm new to JavaMail. I actually started with it last night. I've successfully sent a number of messages, but I randomly get a strange exception for no apparent reason.
If I run the exact same code several times, it will produce this error about every 5 or 6 times:
javax.mail.MessagingException: 250 Requested mail action okay, completed
Does anyone know what might be going on? Thanks in advance for any help you might can give.
Here is the heart of my code:
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host1);
// Get session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress(fromAddress));
// Set the to address
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
// Set the subject
message.setSubject(subject);
// Set the content
message.setContent(content, "text/html");
// Send message
Transport.send(message);
Below is the debugger output: (certain values have been removed for anonymity's sake)
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG: SMTPTransport trying to connect to host "xx.xx.xx.xx", port 25
DEBUG SMTP RCVD: 220 domain.company.com ESMTP MailEnable Service, Version: 1.704-- ready at 01/14/04 14:07:27
DEBUG: SMTPTransport connected to host "xx.xx.xx.xx", port: 25
DEBUG SMTP SENT: EHLO licensing
DEBUG SMTP RCVD: 502
DEBUG SMTP SENT: HELO licensing
DEBUG SMTP RCVD: 250-AUTH LOGIN
250-SIZE 5120000
250-HELP
250 AUTH=LOGIN
DEBUG SMTP: use8bit false
DEBUG SMTP SENT: MAIL FROM:<[email protected]>
DEBUG SMTP RCVD: 250 Requested mail action okay, completed
DEBUG SMTP SENT: RCPT TO:<[email protected]>
DEBUG SMTP RCVD: 250 Requested mail action okay, completed
Verified Addresses
[email protected]
DEBUG SMTP SENT: DATA
DEBUG SMTP RCVD: 250 Requested mail action okay, completed
DEBUG SMTP SENT: QUITBut I am getting that code thrown as a MessageException; the message never goes through. If you look at the debugging output compared to a message that went through, the DATA transmission commands are screwed up.
Thanks for your input, though. I think I've gotten around this by trying to resend the message. It looks like that when I get this exception the message is never sent. I have a catch that detects this exception and tries to resend up to 3 times.
Thanks,
floosh -
Javax.mail.MessagingException: 451 4.3.2 Please try again later
Hi,
Can any one help out to fix following problem.
exception occurred :Sending failed;
nested exception is:
javax.mail.MessagingException: 451 4.3.2 Please try again laterIf this is generated by the server at random, I do not think javamail can not do anything about it. You can add retry logic in your code or figure out why server is giving this error (configuration issue? need to increase any parameters on the server side?).
-
Problems sending email using javax.mail.*
I need to send an email from an application I am working on. I am using the features of the javax.mail package to do so. In looking at the code I am unsure why this is not working. This is my first time using this package so it might be something silly I am missing so any of your thoughts are appreciated. The code is as follows:
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class EmailTester {
public static void main(String[] args) {
try {
//Set the smtp address
Properties props = new Properties();
props.put("mail.smtp.host", args[0] );
// get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
// create a message for this session
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress from =
new InternetAddress( args[1] );
InternetAddress[] to = new InternetAddress[1];
to[0] = new InternetAddress( args[2] );
msg.setFrom(from);
msg.setRecipients(Message.RecipientType.TO, to);
// set the subject and content type
msg.setSubject("subject");
msg.setContent("this is my test email", "text/plain");
// send the email
Transport.send(msg);
catch (MessagingException me) {I have an EMail class that I use at:
http://www.discoverteenergy.com/files/EMail.java
Feel free to use it or compare against your code to see what is different. -
Problem with recognizing javax.mail.* class ?
Hi Folks,
I am new to JavaMail usage on a standalone java program. I did write a java program to send a mail. The problem is it is not recognizing the javax.mail.* class, though i added on the classpath. I too added mail.jar file in the c:\program files\java\jdk1.5.0_16\lib and added the reference same to the classpath and still it is not recognizing. Do i miss something? help me out guys.
Regards,
jaisuryahHi Shannon,
I hope the configuration i did is well. Yah am running the Java from the command line and i dont know why importing the package of javax.mail.* classes are not recognizing. I did unzipped the zip file and placed all the JAR files to lib folder of my installed JDK and referenced the JDK to classpath in environment variable also.
Regards,
Jaisuryah -
Package javax.mail does not exist (Still having trouble)
Good Morning
I know that there are several posts regarding issues with javamail. I have viewed them for the past hour. While several of them address my issue I have been unable to locate a solution.
Bare with me please, I am making this post very thorough. The other threads I have read are frusterating because the problems people tend to post are not clear.
I am trying to run "msgsend" which is a provided demo of javamail-1.4 using command prompt (start - run - cmd) with the javac command.
The output below is directly pasted from command prompt and written in bold.
C:\download\javamail-1.4\demo>javac msgsend.java
C:\download\javamail-1.4\demo>javac msgsend.java
msgsend.java:44: package javax.mail does not exist
import javax.mail.*;
^
msgsend.java:45: package javax.mail.internet does not exist
import javax.mail.internet.*;
^
msgsend.java:140: cannot find symbol
symbol : class Session
location: class msgsend
Session session = Session.getInstance(props, null);
^
msgsend.java:140: cannot find symbol
symbol : variable Session
location: class msgsend
Session session = Session.getInstance(props, null);
^
msgsend.java:145: cannot find symbol
symbol : class Message
location: class msgsend
Message msg = new MimeMessage(session);
^
msgsend.java:145: cannot find symbol
symbol : class MimeMessage
location: class msgsend
Message msg = new MimeMessage(session);
^
msgsend.java:147: cannot find symbol
symbol : class InternetAddress
location: class msgsend
msg.setFrom(new InternetAddress(from));
^
msgsend.java:151: package Message does not exist
msg.setRecipients(Message.RecipientType.TO,
^
msgsend.java:152: cannot find symbol
symbol : variable InternetAddress
location: class msgsend
InternetAddress.parse(to,
^
msgsend.java:154: package Message does not exist
msg.setRecipients(Message.RecipientType.CC,
^
msgsend.java:155: cannot find symbol
symbol : variable InternetAddress
location: class msgsend
InternetAddress.parse(cc,
^
msgsend.java:157: package Message does not exist
msg.setRecipients(Message.RecipientType.BCC,
^
msgsend.java:158: cannot find symbol
symbol : variable InternetAddress
location: class msgsend
InternetAddress.parse(bcc,
^
msgsend.java:167: cannot find symbol
symbol : class MimeBodyPart
location: class msgsend
MimeBodyPart mbp1 = new MimeBodyPart();
^
msgsend.java:167: cannot find symbol
symbol : class MimeBodyPart
location: class msgsend
MimeBodyPart mbp1 = new MimeBodyPart();
^
msgsend.java:169: cannot find symbol
symbol : class MimeBodyPart
location: class msgsend
MimeBodyPart mbp2 = new MimeBodyPart();
^
msgsend.java:169: cannot find symbol
symbol : class MimeBodyPart
location: class msgsend
MimeBodyPart mbp2 = new MimeBodyPart();
^
msgsend.java:171: cannot find symbol
symbol : class MimeMultipart
location: class msgsend
MimeMultipart mp = new MimeMultipart();
^
msgsend.java:171: cannot find symbol
symbol : class MimeMultipart
location: class msgsend
MimeMultipart mp = new MimeMultipart();
^
msgsend.java:185: cannot find symbol
symbol : variable Transport
location: class msgsend
Transport.send(msg);
^
msgsend.java:193: cannot find symbol
symbol : class Store
location: class msgsend
Store store = null;
^
msgsend.java:195: cannot find symbol
symbol : class URLName
location: class msgsend
URLName urln = new URLName(url);
^
msgsend.java:195: cannot find symbol
symbol : class URLName
location: class msgsend
URLName urln = new URLName(url);
^
msgsend.java:212: cannot find symbol
symbol : class Folder
location: class msgsend
Folder folder = store.getFolder(record);
^
msgsend.java:218: cannot find symbol
symbol : variable Folder
location: class msgsend
folder.create(Folder.HOLDS_MESSAGES);
^
msgsend.java:220: cannot find symbol
symbol : class Message
location: class msgsend
Message[] msgs = new Message[1];
^
msgsend.java:220: cannot find symbol
symbol : class Message
location: class msgsend
Message[] msgs = new Message[1];
27 errors
Here are the methods I have tried...
1. Make sure you have most current version of Java
2. Reinstall Java
3. Attempt to compile in an IDE (Attempted in Eclipse 3.2)
4. Set class path
Some sources suggest "CLASSPATH" some suggest "CLASS PATH" as the variable name. I have tried both.
Below is what the classpath looks like in bold.
Variable Name: CLASS PATH
Variable value: c:\download\javamail-1.4\mail.jar;C:\download\jaf-1.1\activation.jar;.
I have double checked all folder names and copy pasted all entries to eliminate typos. Javamail-1.4 and jaf-1.1 are both located in c:\download which is the same location Class Path points to.
Thank you very much for your input and effort. I can imagine how frusterating it is responding to 20million javamail posts :) (that may be a bit of an overstatement!)
Thank you again!
Irbi
Message was edited by:
irbi
Message was edited by:
irbiYes - I have read that part of the README and did exactly as it has said in a previous attempt. I should have mentioned that here I'm sorry :)
I moved the .jar files into the download folder and set the classpath exactly as the readme shows.
When I do that the msgsend.java compiles correctly but it still does not run.
Below is what happens.
C:\download\javamail-1.4\demo>set CLASSPATH=%CLASSPATH%;c:\download\javamail-1.4
\mail.jar;%CLASSPATH%;c:\download\jaf-1.1\activation.jar.
C:\download\javamail-1.4\demo>javac msgsend.java
C:\download\javamail-1.4\demo>java msgsend.java
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend/java
C:\download\javamail-1.4\demo>
I have tried fixing this error as well via forums and FAQs but it seems to be the most generic error.
One suggestion was to clear your classpath. I tried this with a test hello world program which was giving the same error - "NoClassDefFoundError". By clearing the classpath I was able to get the hello world program to run without this error. But I can't just clear the classpath in this instance because it needs to point to mail.jar and activation.jar for the program to compile.
Thanks again for all of your efforts. You are more appreciated than you know. -
Exception in thread "main" javax.mail.NoSuchProviderException: invalid prov
HI,
I am trying to read mails from my inbox i amgetting the ErrorC:\javamail>java
Readmail
Exception in thread "main" javax.mail.NoSuchProviderException: No provider for IMAP
at javax.mail.Session.getProvider(Session.java:455)
at javax.mail.Session.getStore(Session.java:530)
at javax.mail.Session.getStore(Session.java:510)
at Readmail.main(Readmail.java:24)My Code is {
String host = "hostname";
String username = "user";
String password = "password";
// Create empty properties
Properties props = new Properties();
// Get session
Session session = Session.getDefaultInstance(props,null);
// Get the store
Store store = session.getStore("IMAP");
store.connect(host, username, password);
// Get folder
Folder folder = store.getFolder("Inbox");
folder.open(Folder.READ_ONLY);
// Get directory
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++)
System.out.println(i + ": " + message.getFrom()[0]
+ "\t" + message[i].getSubject());
// Close connection
folder.close(false);
store.close();
I have also tried POP3 and MIME and SMTP
Can anyone help me Thankshi bshannon,
I am getting the same error for others but for pop3 the error is as below
Exception in thread "main" javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at Readmail.main(Readmail.java:25)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:81)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)
... 3 more -
I am trying to get hotmail emails and store in Oracle 10g database.
When I am executing receivemail procedure from Oracle 10g database. I am getting following error.
connect to ESIMSCO_UTIL_OWNER
SQL> set serveroutput on
SQL>
SQL> Declare
2 v_error_msg varchar2(10000);
3 Begin
4 v_error_msg:=receivemail('pop3.live.com', '<My email address>@hotmail.com', '<My email password>');
5 dbms_output.put_line(v_error_msg);
6 End;
7 /
javax.mail.AuthenticationFailedException: EOF on socket
PL/SQL procedure successfully completed.
SQL>
I did following steps, but still I am getting this error. Can somebady help me to solve this problem.
connect sys/<password>@esimsco as sysdba
connect to sys
SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 30 16:02:04 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> begin
1 dbms_java.grant_permission( 'ESIMSCO_UTIL_OWNER', 'SYS:java.util.PropertyPermission', '*', 'read,write' );
2 commit;
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> begin
2 dbms_java.grant_permission(
3 grantee => 'ESIMSCO_UTIL_OWNER',
4 permission_type => 'SYS:java.net.SocketPermission',
5 permission_name => '*',
6 permission_action => 'connect,resolve'
7 );
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> begin
2 dbms_java.grant_permission(
3 grantee => 'ESIMSCO_UTIL_OWNER',
4 permission_type => 'SYS:java.util.PropertyPermission',
5 permission_name => '*',
6 permission_action => 'read,write'
7 );
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL>
Then I connect ESIMSCO_UTIL_OWNER.
connect to ESIMSCO_UTIL_OWNER
Create 2 tables.
create table attachment(
at_file varchar2(500),
at_mimetype varchar2(500),
at_attachment blob
create table email (
em_incident integer,
em_from varchar2(1000),
em_subject varchar2(1000),
em_body nclob
Then Create java source named receivemail.
create or replace and compile java source named receivemail as
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
import java.sql.*;
import sqlj.runtime.*;
import oracle.sql.BLOB;
public class ReceiveMail
static void getAttachments(Message message, int incidentNo)
throws MessagingException, IOException, SQLException {
//String attachments = "";
Object content = message.getContent();
if (content instanceof Multipart)
// -- Multi part message which may contain attachment
Multipart multipart = (Multipart)message.getContent();
// -- Loop through all parts of the message
for (int i=0, n=multipart.getCount(); i<n; i++) {
Part part = multipart.getBodyPart(i);
String disposition = part.getDisposition();
if ((disposition != null) &&(disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))) {
//-- This part is a file attachment
String fileName = incidentNo+"_"+part.getFileName().replace(' ','_');
System.out.println("FILE: " + fileName);
String contentType = part.getContentType();
String mimeType = contentType.substring(0,contentType.indexOf(";"));
System.out.println("FILETYPE: " + mimeType);
InputStream is = part.getInputStream();
// -- To work with a BLOB column you have to insert a record
// -- with an emptly BLOB first.
#sql { insert into attachment(at_file, at_mimetype, at_attachment)
values (:fileName, :mimeType, empty_blob()) };
// -- Retrieve the BLOB
BLOB attachment = null;
#sql { select at_attachment into :attachment
from attachment where at_file = :fileName };
// -- Fill the BLOB
OutputStream os = attachment.getBinaryOutputStream();
int j;
while ((j = is.read()) != -1) {
os.write(j);
is.close();
os.close();
// -- Set the BLOB by updating the record
#sql { update attachment set at_attachment = :attachment
where at_file = :fileName };
static String getPlainTextBody(Message message)
throws MessagingException, IOException
Object content = message.getContent();
if (message.isMimeType("text/plain")) {
// -- Message has plain text body only
System.out.println("SIMPLE TEXT");
return (String) content;
} else if (message.isMimeType("multipart/*")) {
// -- Message is multipart. Loop through the message parts to retrieve
// -- the body.
Multipart mp = (Multipart) message.getContent();
int numParts = mp.getCount();
System.out.println("MULTIPART: "+numParts);
for (int i = 0; i < numParts; ++i) {
System.out.println("PART: "+mp.getBodyPart(i).getContentType());
if (mp.getBodyPart(i).isMimeType("text/plain")) {
// -- Return the plain text body
return (String) mp.getBodyPart(i).getContent();
} else if (mp.getBodyPart(i).isMimeType("multipart/*")) {
// -- Body is also multipart (both plain text and html).
// -- Loop through the body parts to retrieve plain text part.
MimeMultipart mmp = (MimeMultipart) mp.getBodyPart(i).getContent();
int numBodyParts = mmp.getCount();
System.out.println("MULTIBODYPART: "+numBodyParts);
for (int j = 0; j < numBodyParts; ++j) {
System.out.println("BODYPART: "+mmp.getBodyPart(j).getContentType());
if (mmp.getBodyPart(j).isMimeType("text/plain")) {
// -- Return the plain text body
return (String) mmp.getBodyPart(j).getContent();
return "";
} else {
System.out.println("UNKNOWN: "+message.getContentType());
return "";
static void saveMessage(Message message)
throws MessagingException, IOException, SQLException
//String body = "";
int incidentNo;
// -- Get a new incident number
#sql { select seq_incident.nextval into :incidentNo from dual };
// -- Get the header information
String from = ((InternetAddress)message.getFrom()[0]).getAddress();
System.out.println("FROM: "+ from);
String subject = message.getSubject();
System.out.println("SUBJECT: "+subject);
// -- Retrieve the plain text body
String body = getPlainTextBody(message);
// -- Store the message in the email table
#sql { insert into email (em_incident, em_from, em_subject, em_body)
values (:incidentNo, :from, :subject, :body) };
// -- Retrieve the attachments
getAttachments(message, incidentNo);
#sql { commit };
// -- Mark message for deletion
// message.setFlag(Flags.Flag.DELETED, true);
public static String Receive(String POP3Server, String usr, String pwd)
Store store = null;
Folder folder = null;
try
// -- Get hold of the default session --
Properties props = System.getProperties();
props.put("mail.pop3.connectiontimeout", "60000");
Session session = Session.getDefaultInstance(props, null);
// -- Get hold of a POP3 message store, and connect to it --
store = session.getStore("pop3");
store.connect(POP3Server,995, usr, pwd);
System.out.println("Connected");
// -- Try to get hold of the default folder --
folder = store.getDefaultFolder();
if (folder == null) throw new Exception("No default folder");
// -- ...and its INBOX --
folder = folder.getFolder("INBOX");
if (folder == null) throw new Exception("No POP3 INBOX");
// -- Open the folder for read_write (to be able to delete message) --
folder.open(Folder.READ_WRITE);
// -- Get the message wrappers and process them --
Message[] msgs = folder.getMessages();
for (int msgNum = 0; msgNum < msgs.length; msgNum++){
saveMessage(msgs[msgNum]);
System.out.println("No more messages");
return ("SUCCESS");
catch (Exception ex){
ex.printStackTrace();
return ex.toString();
finally{
// -- Close down nicely --
try{
// close(true), to expunge deleted messages
if (folder!=null) folder.close(true);
if (store!=null) store.close();
catch (Exception ex){
//ex.printStackTrace();
return ex.toString();
Then create function receivemail.
create or replace function receivemail(pop3_server in string,
pop3_usr in string,
pop3_pwd in string)
return varchar2
is language java name
'ReceiveMail.Receive(java.lang.String,
java.lang.String,
java.lang.String) return String';
And then trying to execute function receivemail, but I am getting following error.
SQL> set serveroutput on
SQL>
SQL> Declare
2 v_error_msg varchar2(10000);
3 Begin
4 v_error_msg:=receivemail('pop3.live.com', '<Hotmail email address>@hotmail.com', 'Hotmail password');
5 dbms_output.put_line(v_error_msg);
6 End;
7 /
javax.mail.AuthenticationFailedException: EOF on socket
PL/SQL procedure successfully completed.
SQL>
I am requesting, please help me to solve this problem.
I will be very thankful for your kind help and support.
Amol......
Edited by: Amol Karyakarte on 31-May-2012 7:27 AMHello,
I don't think this is the right forum, as this question seems to have nothing to do with the Oracle Forms tool.
You'd better ask it in the database forum.
Francois -
How to get support of javax.Mail in Tomcat
Hello
I am tring to run a program which need javax.MAil and javax.activation packages in jsp. i am using tomcat
but i am not able to run that program as it giving error of package not found . so plz tell me how i can use other API's in tomcat
regards
RajHello sir thx for ur reply ...but i already did that on
means set classpath for both jar files
r there any classpath variable in tomcat also?
as i set my local classpath environment variable
when i import that package that is javax.mail
it gives me error on import statement...i thing
when we import any package it searchs that package
in WEB-INF/class dir...so plzz....reply and give me
ome suggestions. -
Javax.mail CSV file attachment corrupt?
I'm having some trouble with attaching a file to an outgoing email, it's a CSV file and when it is uploaded/attached to the email, it becomes "corrupt". Excel will still open it but if I open it in notepad the formatting is noticeably messed up. I need it to retain all the correct return carriages and line feeds, which I believe are what are getting mingled. (Another program must read it and this formatting is messing everything up).
Here's the code:
MimeBodyPart messageBodyPart =
new MimeBodyPart();
//fill message
messageBodyPart.setText(outBoundMessage);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
if (fileAttachment != null) {
// Part two is attachment
MimeBodyPart attachment = new MimeBodyPart();
attachment.attachFile(fileAttachment);
attachment.setFileName(fileAttachment.getName());
attachment.setHeader("type", "text/csv");
multipart.addBodyPart(attachment);
// Put parts in message
message.setContent(multipart);The other parts of the message are being created and attached where necessary. My guess is that it's not transferring in binary? I've never really done this sort of thing so if anyone could lend a hand and show me how to properly attach files so they don't get altered in anyway I would greatly appreciate it.Hi,
I am sending csv file as an attachment by using below code
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class AttchmtMail
String finaldt;
public void mailAtchmt(String fname,String dt) {
String to="[email protected]";
String from = "[email protected]";
String to2="[email protected]";
String host = "xxx.xx.xxx.xxx";
// Create properties, get Session
Properties props = new Properties();
// If using static Transport.send(),
// need to specify which host to send it to
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
Session session = Session.getInstance(props);
try {
// Instantiatee a message
Transport bus = session.getTransport("smtp");
bus.connect();
Message msg = new MimeMessage(session);
//Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to),new InternetAddress(to2)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("New OU's on "+dt+".");
msg.setSentDate(new Date());
// String filename= "C:/Feeds/"+finaldt+"/"+files;
String file1= fname;
File f1=new File(file1);
if(f1.exists())
setFileAsAttachment(msg, file1);
else
//setFileAsAttachment(msg,"","",info);
msg.saveChanges();
bus.sendMessage(msg, address);
bus.close();
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
// How to access nested exceptions
while (mex.getNextException() != null) {
// Get next exception in chain
Exception ex = mex.getNextException();
ex.printStackTrace();
if (!(ex instanceof MessagingException)) break;
else mex = (MessagingException)ex;
public void setFileAsAttachment(Message msg, String filename)
throws MessagingException {
// Create and fill first part
MimeBodyPart p1 = new MimeBodyPart();
p1.setText("Dear ,\n\nPlease check the attachment " );
// Create second part
MimeBodyPart p2 = new MimeBodyPart();
// Put a file in the second part
if(!filename.equals(""))
FileDataSource fds = new FileDataSource(filename);
p2.setDataHandler(new DataHandler(fds));
p2.setFileName(fds.getName());
// Create the Multipart. Add BodyParts to it.
Multipart mp = new MimeMultipart();
mp.addBodyPart(p1);
if(!filename.equals(""))
mp.addBodyPart(p2);
} // Set Multipart as the message's content
msg.setContent(mp);
}//End of class
Madhu -
Import statement not found for javax.mail.Message
when i'm in webSphere shich is using jdk1.4.2,
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
cannot be found
Where would the Mail classes be located?
Thank youmail.jar and activation.jar, which can be downloaded here:
http://java.sun.com/products/javamail/downloads/index.html
http://java.sun.com/products/javabeans/jaf/downloads/index.html -
Javax.mail.internet.ParseException when trying to send a MIME message
Hi,
I am using JavaMail to send a MIME message, but I am getting the following exception:
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Compiled Code)
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Compiled Code)
at javax.mail.MessagingException.<init>(MessagingException.java:34)
at javax.mail.internet.ParseException.<init>(ParseException.java:27)
at javax.mail.internet.ParameterList.<init>(Compiled Code)
at javax.mail.internet.ContentType.<init>(ContentType.java:82)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1051)
at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1923)
at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1904)
at javax.mail.Transport.send(Transport.java:101)
at FPSend.main(Compiled Code)
The problem seems to be the header of the message, specifically the class-id filed of the content-type. This is the content-type header that causes javaMail to throw that exception:
Content-Type: multipart/alternative;
boundary="------------110059296832670";
class-id=11:9sc9bnYwM87box:2680047
I think the ":" character in the class-id is causing the problem. Does anybody know if those characters are valid according to MIME standards? And if they are not valid, is there a work around this problem?
thank you!RFC 2046 doesn't mention the existence of the class-id parameter. But it does say this:Thus, a typical "multipart" Content-Type header field might look like this:
Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08j34c0p
But the following is not valid:
Content-Type: multipart/mixed; boundary=gc0pJq0M:08jU534c0p
(because of the colon) and must instead be represented as
Content-Type: multipart/mixed; boundary="gc0pJq0M:08jU534c0p"From what I see elsewhere, Class-ID is a Microsoft extension. It wouldn't be surprising to find that Microsoft uses extensions that are incompatible with the MIME standards. -
Error using javax.mail package
Hi,
I have included the package javax.mail.* in my code.I have downloaded
jaf 1.0.2 and javamail 1.1.3 from the Sun Microsystems website.
When i try to compile my code i get the error message:
com/voxspectrum/ccvox/EmailServer.java:55: cannot resolve symbol
symbol : class MimeMessage
location: class com.voxspectrum.ccvox.EmailServer
javax.mail.Message msg = new MimeMessage(session);
I am using JDK ver 1.3.1_02. What should i set my path and classpath as, if i am using javax.mail package?
Please could you help me out with this problem!Hi Nisha
You need to include the path to the mail.jar and activation.jar files in your classpath.
How you do it depends on the OS you are running on
in Windows 95 /98 the easiest way is to edit the autoexec.bat file and add the settings to your already existing classpath statement i.e.
set CLASSPATH=%CLASSPATH%;C:\richard\javamail-1.3\mail.jar C:\richard\jaf-1.0.2\activation.jar
(excuse the word wrapping) then reboot
on Linux / Solaris edit the .profile file for your user and set the CLASSPATH variable to
CLASSPATH=$CLASSPATH:<pathtofile>/mail.jar:<pathtofile>/activation.jar
export CLASSPATH
and that should do it
Hope this helps -
Error: Javax.mail does not exist, please help
I have copies mail.jar and activation.jar in the classpath directory as instructed, then try to compile but got the below error: package javax.mail does not exist
please help.
G:\CRD>javac SendMailBean.java
SendMailBean.java:22: package javax.mail does not exist
import javax.mail.*; //JavaMail packages
^
SendMailBean.java:23: package javax.mail.internet does not exist
import javax.mail.internet.*; //JavaMail Internet packages
^
SendMailBean.java:43: cannot resolve symbol
symbol : class Session
location: class SendMailBean
Session l_session = Session.getDefaultInstance(l_props, null);
^
SendMailBean.java:43: cannot resolve symbol
symbol : variable Session
location: class SendMailBean
Session l_session = Session.getDefaultInstance(l_props, null);
^
SendMailBean.java:48: cannot resolve symbol
symbol : class MimeMessage
location: class SendMailBean
MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
^
SendMailBean.java:48: cannot resolve symbol
symbol : class MimeMessage
location: class SendMailBean
MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
^
SendMailBean.java:50: cannot resolve symbol
symbol : class InternetAddress
location: class SendMailBean
l_msg.setFrom(new InternetAddress(p_from)); // Set the From address
^
SendMailBean.java:53: package Message does not exist
l_msg.setRecipients(Message.RecipientType.TO,
^
SendMailBean.java:54: cannot resolve symbol
symbol : variable InternetAddress
location: class SendMailBean
InternetAddress.parse(p_to, false));
^
SendMailBean.java:57: package Message does not exist
l_msg.setRecipients(Message.RecipientType.CC,
^
SendMailBean.java:58: cannot resolve symbol
symbol : variable InternetAddress
location: class SendMailBean
InternetAddress.parse(p_cc, false));
^
SendMailBean.java:62: package Message does not exist
l_msg.setRecipients(Message.RecipientType.BCC,
^
SendMailBean.java:63: cannot resolve symbol
symbol : variable InternetAddress
location: class SendMailBean
InternetAddress.parse(p_bcc, false));
^
SendMailBean.java:68: cannot resolve symbol
symbol : class MimeBodyPart
location: class SendMailBean
MimeBodyPart l_mbp = new MimeBodyPart();
^
SendMailBean.java:68: cannot resolve symbol
symbol : class MimeBodyPart
location: class SendMailBean
MimeBodyPart l_mbp = new MimeBodyPart();
^
SendMailBean.java:72: cannot resolve symbol
symbol : class Multipart
location: class SendMailBean
Multipart l_mp = new MimeMultipart();
^
SendMailBean.java:72: cannot resolve symbol
symbol : class MimeMultipart
location: class SendMailBean
Multipart l_mp = new MimeMultipart();
^
SendMailBean.java:83: cannot resolve symbol
symbol : variable Transport
location: class SendMailBean
Transport.send(l_msg);
^
SendMailBean.java:98: cannot resolve symbol
symbol : class MessagingException
location: class SendMailBean
} catch (MessagingException mex) { // Trap the MessagingException Error
^
19 errorsAnother person who doesn't understand how to set CLASSPATH.
Move those JARs into the same directory as your SendMailBean.java and do it like this:
javac -classpath .;mail.jar;activation.jar -d . *.java
java -classpath .;mail.jar;activation.jar SendMailBeanRead how to set CLASSPATH properly:
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html
Maybe you are looking for
-
Problem with self developed adapter
hi all, i am developing an own adapter. It is pretty much the sample adapter copied from the PCK. After i deployed it, i uploaded the CPA cache metadata. If i select "Show All" in the Adapter Monitor (part of the Integration Monitor) i can see the ad
-
I'm on CC on Windows 7 x64 and I get this error everytime I try to install LR5 through AAM: ERROR: Third party payload installer Install Lightroom 5 CCM.exe failed with exit code: 1612 Any ideas?
-
Firefox doesn't list javascript in preference content. How do I enable javascript?
"Enable javascript" not listed as an option on firefox content preferences. How do I enable javascript?
-
Tried disk utility, restarts, any other suggestions would be appreciated. Thanks!
-
Sharing with Mac OS X 10.6.2
I'd like to share my files from a Mac OS X 10.4.11 to a Mac OS X 10.6.2,i try many times but i can't do that. I'd like to create a wireless network computer to computer and share files to my new computer Somebody could help me?