Javax.mail help
I need help on sending email through java
I have manage to send text message only but ehen i see the doucmentation in the webpage, it say it is able to send not just text how do i send it?
I seen the source code:
ByteArrayOutputStream byteStream=new ByteArrayOutputStream();
ObjectOutputStream objectStream=new ObjectOutputStream(byteStream);
objectStream.writeObject(theObject); but if it is a file that i need to attach?
http://java.sun.com/products/javamail/FAQ.html#attach
Similar Messages
-
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 -
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 -
Help to solve javax.mail.AuthenticationFailedException: EOF on socket
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......Amol Karyakarte wrote:
I am requesting, please help me to solve this problem.
I will be very thankful for your kind help and support.
Amol......since you asked for it:
http://lmgtfy.com/?q=javax.mail.AuthenticationFailedException
First hit
Session session = Session.getDefaultInstance(props, null);Is null correct?
Regards -
Please help! javax.mail.SendFailedException is killing me
im trying to send myself an email through javax.mail and this is the error i get: it is thrown from Transport.send(msg);i dont have access to its source so i cannot trace through it... can anyone please tell me what might cause this error?
javax.mail.SendFailedException: 550 <[email protected]>: Recipient address rejected: Relay access deniedHi,
I'm trying to send mail thro a servlet.
When I use host as 'mail.vsnl.com'
It gives the following exeception
Relay access denied
can U help me!
thanks in adv.
Isaaac -
Package javax.mail does not exist. Please Help !
Hi all,
I am new to Java and I downloaded some sample application and when I try to compile it, I get an error:
"package javax.mail does not exist".
I've looked through forums and I know something is wrong with CLASSPATHS and that I also have to download the java mail package, but I dont know how to exactly fix this problem. I would appreciate very much if someone could help me, maybe by telling me the steps I need to take.
Thanks.Hey Rom,
Thanks for reply.
The sample application is an authentication module:
http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/tutorials/GeneralAcnOnly.html
But I think this doesnt really matter, as the error I get is because I have manually added the : import java.mail.*; statement. (Maybe I had to mention it in the previous post). Because I want to add some mail client inside.
I am compiling it using the command: javac, from the commandline menu. -
[help] javax.mail.SendFailedException
What it means?
javax.mail.SendFailedException: Invalid Addresses; nested exception is: class com.sun.mail.smtp.SMTPAddressFailedException: 553 sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1)
I use javax.mail API to send email from java servlet using a .info smtp server.
It is the domain .info that create this error?
Can i resolve?
I tryed with a .it smtp server but it doesn't change...only with the server smtp of my ISP the mail was send correctly!
Sorry for my english...Help Me!The SMTP server you use does not allow relaying mesages from/to the specified domain. Example: you cannot use yahoo's SMTP server to relay an email to [email protected] Change your rcpthosts on the SMTP server.
-
Javax.mail problem...can any1 help
Hi all;
me am using javamail version 1.3 to send simple text mail using smtp server...during compilation, no error arises but while running following exception arises;
Sending failed; nested exception is: javax.mail.SendFailedException: Invalid Addresses; nested exception is: javax.mail.SendFailedException: 550 5.7.1 ... Relaying denied ; nested exception is: javax.mail.SendFailedException: 550 5.7.1 ... Relaying denied ; nested exception is: javax.mail.SendFailedException: 550 5.7.1 ... Relaying denied
wat should i do...where does the problem lie...
would b waiting desperately for immediate replies.
Regardswhile executing the above mentioned code...following errors come out...
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 <[email protected]>... Relaying denied
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 <[email protected]>... Relaying denied
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 <[email protected]>... Relaying denied
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at __27eayyaz._msgsend__jsp._jspService(/~ayyaz/msgsend.jsp:25)
at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:181)
at com.caucho.server.http.Invocation.service(Invocation.java:291)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:341)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:268)
at com.caucho.server.TcpConnection.run(TcpConnection.java:136)
at java.lang.Thread.run(Thread.java:544) -
Please help me!!javax.mail.SendingFailedException
I use javamail to send email,
but it throws javax.mail.SendingFailedException,
and it says the receiver is invalid address,
but I am sure the receiver is valid!
What's the problem?
Many Thanks!What is the full stack trace, what address are you sending to, and a code segment would be nice. It's kind of hard to debug if you don't have any useful information.
-
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 -
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 -
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 -
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 -
Javax.mail.MessagingException: 505 Client was not authenticated
Hi!,
I got the following error:
Exception in thread "main" javax.mail.MessagingException: 505 Client was not authenticated
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:507)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:312)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:168)
at HelloMail.main(HelloMail.java:35)
This is the code:
To send an email I need authentification, and I include the mail.smtp.auth propertie and
"message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect("mail.xxx.com.mx","harriaga",passw);
transport.sendMessage(message,message.getAllRecipients());
transport.close();"
Do you know if I am skip something.
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class HelloMail {
public static void main(String args[]) throws Exception {
String host="mail.xxx.com.mx"; //obviously doesn't work
String from="[email protected]"; //sender's email
String to ="[email protected]" ; //receiver's email
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Session session=Session.getInstance(props,null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
message.setSubject(" My Test HTML email ");
message.setText(" Here is the content ");
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect("mail.xxx.com.mx","harriaga",passw);
transport.sendMessage(message,message.getAllRecipients());
transport.close();
Thanks for all,
HAG.HAG,
you need to create a session object passing a valid authenticator. In other words,
MyAuthenticator auth = new MyAuthenticator ();
Session session = Session.getInstance(props, auth);where MyAuthenticator is something like
public class MyAuthenticator extends Authenticator{
public PasswordAuthentication getPasswordAutentication(){
return new PasswordAuthentication( "user", "password");
}You obviously need to replace username and password with data valid for your e-mail account.
Hope this helps,
gulfi -
Problem importing javax.mail.*
Hey,
I just installed the Java JDK 6 update 16 (windows platform). I am not able to compile a sample code that used the javax.mail package. I am not able to get past the
import javax.mail.*;
line. The compiles says "package javax.mail does not exist"
I tried separately installing the JavaMail 1.4.2 API and setting the classpath to the mail.jar file as suggested in the readme.txt for this API, but I still get the same problem. Anyone has any suggestions?
Thanks!Hi! I see you've answered similar problems before - but nothing seems to be working for me.
My OS is Vista. I installed the JDK 6 update 16 just yesterday. I'm using the command line javac.
I can see the mail.jar file in this folder: C:\Sun\SDK\lib\ and I've set the classpath using : set classpath=%classpath%;C:\Sun\SDK\lib\mail.jar
When I type set classpath at the prompt, I can see that the classpath has been set correctly.
Please help!
Maybe you are looking for
-
What is the audio line-in impedance?
I am trying to use Via Voice 3 to write. I have Parkinson's and typing is becoming more difficult. (Although VV 3 is not too smooth in OSA X 10.3.9, it works fairly well using NeoOffice as the WP). The Andrea headset/mic that came with VV is junk, so
-
Sub-contracting operation.
Hi, we have one sub-contracting operation in between in-house production order operations. For sub-contracting operation only the in-process semi finished material which is the result of previous operation will be sent to vendor. While I am trying to
-
How We can restrict the max no of Selections in JList
Hi, How We can restrict the max. no of selections (at random selections) in JList (ex. max No of of selections is 3 in a JList of having 50 items.) Thanks for your advise in advance.
-
Any way to import svg file?
I used to be able to convert an svg file using terminal... but that doesn't work anymore... Any suggestions?
-
Unable to edit my code in JDeveloper. I checked with all the options in the menu. Please help regarding this.