Trying javax.mail
Im trying to getsome code to work for me that sends mail via the javax.mail protocol or api sorry.....anywho i get the mail to send and everything is great will somebody tell me if javax.mail has a simple attachment feature in it i need to attach a file now that it is sending........ maybe i could send my code to send it and someone can walk me through attaching a file before sending it.....im very new at this so
Hi, you can try something like this:
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
* @author Christopher Cotton
public class sendfile {
public static void main(String[] args) {
if (args.length != 5) {
System.out.println("usage: java sendfile <to> <from> <smtp> <file> true|false");
System.exit(1);
String to = args[0];
String from = args[1];
String host = args[2];
String filename = args[3];
boolean debug = Boolean.valueOf(args[4]).booleanValue();
String msgText1 = "Sending a file.\n";
String subject = "Sending a file";
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getInstance(props, null);
session.setDebug(debug);
try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
// create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
// set the Date: header
msg.setSentDate(new Date());
// send the message
Transport.send(msg);
} catch (MessagingException mex) {
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
}
Similar Messages
-
Javax.mail.mailexception while am trying to send the mail
Hi.
Am trying to send a mail from ADF Application am using SMTP Server to send the mail
I have added javamail.jar in my libraries
This is the code am using to send
public String send() {
// Add event code here...
String to;
to = new String();
String host = "localhost";
String from = "[email protected]";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage (session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress("to"));
message.setSubject(subj);
message.setText(body);
Transport.send(message);
System.out.println ("Sent Message Successfully");
catch(MessagingException max){
max.printStackTrace();
return null;
}Am getting the exception as below
javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1321)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:637)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at view.SendMail.send(SendMail.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(Unknown Source)
at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
Could any one pls help me?
regards,
Prasad K T.This question is better asked in a java forum or JavaMail forum {forum:id=975}
Timo -
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. -
Trying to import javax.mail.*
hi,
I need to make a sort of webmail program for school, i understand most of the things I've read so far about it but when i actually try to program and import javax.mail.* and javax.mail.internet.* Together (the compiler we have to use) doesn't recognise these import
any help would be appreciated because i'm dying to get started :)Hi,
You need to have java mail jar files in your classpath.
They are available for download at http://java.sun.com/products/javamail/downloads/index.html
-Amol -
Any help on the below error would be appreciated?
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: can't determine local email address
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at com.rightworks.maildispatcher.MailDispatcher$SenderThread.sendMessage
(MailDispatcher.java, Compiled Code)
at com.rightworks.maildispatcher.MailDispatcher$SenderThread.run(MailDis
patcher.java:536)
Cannot send mail file s1io.d.xml : Sending failed;
nested exception is:
javax.mail.MessagingException: can't determine local email addressAppears to be related to specifing the mail.from input.
Works now. -
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 -
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 Error while writing spool file??
Hi all friends,
Can any one plz tell me why Iam getting below error when Iam trying to send mail with attachment.Iam using Java Mail API.
javax.mail.MessagingException: 451 Error while writing spool file
Plz tell me what are the reasons behind it.
Regards
BikashThe problem here is that the SMTP server was unable to write its spool file.
The error is probably on the OS side of things and has nothing to do with email except that the lack of the system resource is causing email to fail.
Have the server admin take a look at his error log to find out why the the user that smtp is running as could not write the file. -
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 -
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! -
SOAP and javax.mail.internet.ContentType
Hi there,
I have a problem with a very simple SOAP app:
I get a saaj error "Unable to internalize message", which gets caused by a
NoClassDefFoundError: javax/mail/internet/ContentTypeI have tried everything:
1) Copied mail.jar to ./jre/lib/ext
2) Added the directory containing mail.jar to the CLASSPATH, in Windoze and in Sun ONE Studio
When I try to instantiate javax.mail.internet.ContentType in the same app, it works fine, i.e. the class can be found, but saaj doesn't see it for some strange reason.
Any ideas?
I am using the Web Services pack 1.3 and java version:
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)Thanks in advance
AndiYou also need to have the Java Activation Framework available (activation.jar).
The NoClassDefFoundErr can me caused by a class being used by a class not being found. -
WLS5.1 SP8: using javax.mail
Hi All,
I've just managed to use the javax.mail package to send email from a session
bean, but I'm not happy with the way I did it and I had to hack the
solution, rather than follow the recommended way:
In my weblogic.properties file, I have;
weblogic.resource.MailSession.weblogic.resource.mail.EBCSession=\
mail.from=[email protected], \
mail.host=mail.fluid.com.au
which seems to be correct according to
http://www.weblogic.com/docs51/classdocs/API_ejb/EJB_environment.html#102218
2
When I start WLS, it indicated that it's bound the JNDI name without error
However, in my session bean, I kept getting a runtime error as the session
was trying to connect to a server on localhost, instead of
"mail.fluid.com.au". In other words, it didn't seem to be using the
mail.host setting in weblogic.properties.
I managed to solve the problem by doing this:
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", Utility.getProperty("ebc.mail.host"));
// use mail address from HTML form for from address
props.put("mail.from", "[email protected]");
and sending the props object when creating the session AND THIS WORKED!
I'd prefer to configure the mail session only in weblogic.properties, so is
there another step I need to take to make WLS see/use the mail.host I have
set in weblogic.properties?
Thanks all for your time.
byeeeeeeeeeeeeeeeeeeeeeThe 'nice' way to do what you want is to have your realm implement
the ManageableRealm interface and call those methods instead of
changing the database directly from the Bean.
Also make sure your realm has a way to refresh it's cache (if you
use one) when Users/Groups/ACLs are added/changed in your underlying
data store.
-Don
"Andy Marks" <[email protected]> wrote:
Hi All,
I've hacked the rdbmsrealm example from the standard WLS5.1
install to use
the schema in my Oracle 8.1.6 database instread of the
cloudscape db, and
everything is fine. However...
I'm a little in the dark about how much interaction my
EJBs should have with
the realm? I initially had a bean which controlled user
creation by
populating the same database table that is now mapped
to by my
realm.properties. Should I now delegate the user creation
to the realm
classes instead of my bean?
I've looked through what I think is all the documentation,
but still cannot
really find the "how is it used" information I require.
byeeeeeeeeeeeeeeee
Thanks in advance. -
Reading Inbox - javax.mail.MessagingException: Connect failed;
I get an error message while trying to read emails by connecting to a company mailbox. The message is as follows:
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection refused: no further information
boolean com.sun.mail.pop3.POP3Store.protocolConnect(java.lang.String, int, java.lang.String, java.lang.String)
void javax.mail.Service.connect(java.lang.String, int, java.lang.String, java.lang.String)
void javax.mail.Service.connect(java.lang.String, java.lang.String, java.lang.String)
void GetMessageExample.main(java.lang.String[])
The code is very simple and as follows:
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class GetMessageExample {
public static void main (String args[]) throws Exception {
String host = "companyname.com";
String username = "user";
String password = "xxxx";
try{
// Create empty properties
Properties props = new Properties();
// Get session
Session session = Session.getInstance(props, null);
// Get the store
Store store = session.getStore("pop3");
store.connect(host, username, password);
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));
// 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();
} catch (Exception e) {
e.printStackTrace();
I have a two part question:
1. At home I am using a dial-up connection it works when I change the settings to an email account as provided by the local ISP.
I have tried it with both "pop3" and "imap" in
Store store = session.getStore("pop3");
for the company email but it does not work.
Is this a problem with company security? Maybe firewall/proxy error? If so how do I get around it?
2. Also, when I am in the office (LAN used to connect to Internet) I cannot even get a connection to the ISP account - similar problem or different?
Any thoughts and help most appreciated.
Thanks in advance,
MarkIt could be that the mail server is not accepting connections from the machine you are on. Have you tried using Outlook Express or the Netscape email client to connect to the server/account from the machine that is getting the failure?
Maybe you are looking for
-
My ipod touch does not sync with itunes 10.5
i have windows 7 and wen i updated my itunes from itunes 9 to the latest version of itunes 10.5 i had a hard time getting itunes to open but now that i finally got itunes open and updated it says that my ipod can not be found because the required sof
-
Hp laserjet 3055 will not print double sided
Okay, it worked before, but the scanner scanner software always crashed when I used it. So I thought I would reinstall the printer driver and see if that would let me scan. Well, the scanner software still crashes, but even worse there is no longer a
-
Safari 6.0.5 develop menu
safari 6.0.5! I am using safari 6.0.5 and can't see on the "develop" menu "disable/enable runaway javascript timer. Can anyone help?
-
Urgent- Printing JPanel problem
I want to print a JPanel by calling a Print utility class. JPanel is drawing with different shapes (Rectangle2D etc..) The problem is that I can only print the first page of the JPanel. My Print utility: import java.awt.*; import javax.swing.*; impor
-
Viewing Swatches in Bridge for CS5
I have a fairly large number of swatches created in CS3 and CS4 and saved as .ASE files. In the older Bridge (v3.0.0.464), I could display my user library file and see the colors in each swatch. When I display my user library in the Bridge that ins