HI, Iam  trying to Integrate Exchange server using Java Mail

Here is what iam stuck with, I have a problem while conneting to Exchange Server using imap over ssl.
My code looks like this
props.put("mail.imap.host",host);
props.put("mail.imap.sasl.authorizationid","user1");
props.put("mail.imap.sasl.enable","true");
props.setProperty("mail.imap.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imap.socketFactory.fallback","true");
props.setProperty("mail.imap.socketFactory.port","993");
Authenticator auth = new myauthenticator(AdminUserName,AdminPassword);
Session session = Session.getInstance(props,auth);
session.setDubug(true);
Store store = session.getStore("imap");
store.connect();
I get the following Exception as
javax.mail.MessagingException: Software caused connection abort: recv failed;
nested exception is:
java.net.SocketException: Software caused connection abort: recv failed
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:571)
at javax.mail.Service.connect(Service.java:310)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at MoveCalendar.move(MoveCalendar.java:63)
at SendCalendar.send(SendCalendar.java:74)
at SendCalendar.main(SendCalendar.java:40)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.a(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(Unknown Source)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:97)
at com.sun.mail.iap.Response.<init>(Response.java:96)
at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:61)
at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:135)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:261)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:114)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
... 6 more
DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: enable SASL
DEBUG: mail.imap.sasl.authorizationid: user1
If i change the sessionFactory.class or if I remove this property I donot get any Exception It gets Executed well, but IT goes directly to the Adminstrators Mail account but not to the AuthorizationId I gave it. Can any one give me sugssion upon this issue.I don't understand whether the problem was with the Exchange Server I was trying to connect or with my local Environment

hi,
Iam very thankful for your reply here's the requested debug steps
DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: enable SASL
DEBUG: mail.imap.sasl.authorizationid: user1
DEBUG: protocolConnect returning false, host=india.lendingspace.com, user=PMaganti, password=<null>
* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lsinmail.india.lendingspace.com) ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN AUTH=NTLM
A0 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
DEBUG: protocolConnect login, host=****, user=AdminUserName, password=<non-null>
IMAP SASL DEBUG: Mechanisms: NTLM
IMAP SASL DEBUG: No SASL support
A1 LOGIN AminUserName AdminPassword
A1 OK LOGIN completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN AUTH=NTLM
A2 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
DEBUG: connection available -- size: 1
A3 SELECT INBOX
* 1 EXISTS
* 1 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UNSEEN 1] Is the first unseen message
* OK [UIDVALIDITY 261914] UIDVALIDITY value
A3 OK [READ-WRITE] SELECT completed.
No of Messages msgs 1
A4 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 1 FETCH (ENVELOPE ("5 Mar 2009 13:25:19 +0530" "Outlook Calendar Events Using Java" ((NIL NIL "XXXXX" "XXXXX")) ((NIL NIL "XXXXX" "XXXXX")) ((NIL NIL "XXXXX" "XXXXX")) ((NIL NIL "XXXX" "XXXX")) NIL NIL NIL "<XXXXX>") INTERNALDATE " 5-Mar-2009 13:25:19 +0530" RFC822.SIZE 1348)
A4 OK FETCH completed.
FROM: XXXX
SUBJECT: Outlook Calendar Events Using Java
DATE: Thu Mar 05 13:25:19 IST 2009
A5 FETCH 1 (BODYSTRUCTURE)
* 1 FETCH (BODYSTRUCTURE (("TEXT" "CALENDAR" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 598 10 NIL NIL NIL) "mixed" ("boundary" "----=_Part_0_18680399.1236239719654") NIL NIL))
A5 OK FETCH completed.
[ Multipart Message ]
CONTENT:TEXT/CALENDAR; charset=US-ASCII
A6 STORE 1 +FLAGS (\Answered)
* 1 FETCH (FLAGS (\Answered \Recent))
A6 OK STORE completed.
A7 COPY 1 CALENDAR
A7 OK [COPYUID 262745 258 23] COPY completed, 1 messages copied.
A8 EXAMINE INBOX
* 1 EXISTS
* 0 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS ()] Permanent flags
* OK [UNSEEN 1] Is the first unseen message
* OK [UIDVALIDITY 261914] UIDVALIDITY value
A8 OK [READ-ONLY] EXAMINE completed.
A9 CLOSE
A9 OK CLOSE completed.
DEBUG: added an Authenticated connection -- size: 1
A10 LOGOUT
* BYE Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 signing off.
A10 OK LOGOUT completed.
DEBUG: IMAPStore connection dead
DEBUG: IMAPStore cleanup, force false
DEBUG: IMAPStore cleanup done
Actually what iam doing is read a mail which was more recent in inbox and If it is an Calendar event Iam copying that mail to Calendar Folder. So that Microsoft OUTLOOK automatically recongnizes them and secudles them in it's Calendars
This is actually done for adminstrator's Account but not for the user1
As you have suggested I removed the socketFactory class stuff and did this.
and this is my modified Code
props.put("mail.imap.host",imapHost);
props.put("mail.imap.sasl.enable", "true");
props.put("mail.imap.sasl.authorizationid", "user1");
Authenticator auth=new myauthentication(imapUserName,imapPassword);
Session session = Session.getInstance(props,auth);
session.setDebug(true);
store = session.getStore("imap");
store.connect();
And that goes like that.

Similar Messages

  • Problem to access POP3 of MS Exchange Server using Java Mail

    {color:#0000ff}Hi,
    I have a requirement to read emails from my office mailbox using POP3 protocol which is in Microsoft Exchange Server.
    My code is given below.{color}
    {color:#0000ff}*package emailadaptor;*
    import java.util.Properties;
    import javax.mail.Session;
    import javax.mail.Store;
    *public class Test {*
    *public static void main(String[] args) {*
    * // POP3 server name of Exchange Server*
    * String host = "popServer.domain.com";*{color}
    {color:#0000ff}*
    * // User name*
    * String user = "domainName\\userName";*
    * String password = "password";
    * // Get a session. Use a blank Properties object.*
    * Session session = Session.getDefaultInstance(new Properties());
    * try{*
    * // Get a Store object*
    * Store store = session.getStore("pop3");*
    * store.connect(host, user, password);*
    * }catch(Exception e){*
    * e.printStackTrace();*
    *{color:#0000ff}I can ping popServer.domain.com from my machine where I am testing the code.*
    For username I have tried with domainName\\userName and username pattern both but unsuccessful. For example if my username if user1 and my domain name is domain1 than the two patterns I have tried are &lsquo;domain1\\user1&rsquo; and &lsquo;user1&rsquo;.
    For both these cases I am getting same error, and below is my error stack Trace.
    *{color}*
    *{color:#ff0000}javax.mail.AuthenticationFailedException: The requested mailbox is not available on this server.*
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:158)
    at javax.mail.Service.connect(Service.java:291)
    at javax.mail.Service.connect(Service.java:172)
    at emailadaptor.Test.main(Test.java:19)
    *{color}*
    *{color:#0000ff}Please give me some idea and steps what is wrong with this code and if any other information is needed then also let me know that.*
    Please help.
    Regards,
    *Gourab{color}
    *{color}

    Turn on session debugging. What does the protocol trace show?
    Are you able to connect with other mail clients, such as Thunderbird?
    (Outlook doesn't count.)

  • How can i access gmail's smtp server using java mail api

    i m using java mail api to access gmails pop and smtp service to receive and send mail from ur gmail account. I m able to access gmails pop server using the ssl and port 995 , but i can not use its smtp server to which i m connecting using ssl on 465 port. It requires authentication code.
    if anybody can help me in this regard i m thnkful to him/her.
    thnks in advance.
    jogin desai

    Here's an example of using SSL + Authentication
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=ssl+authentication&subCat=siteforumid%3Ajava43&site=dev&dftab=siteforumid%3Ajava43&chooseCat=javaall&col=developer-forums

  • How to use Java Mail API in Unix

    I am trying to write some code using Java mail API. I want to execute it in Unix. I downloaded the mail API to windows machine and ftped the mail.jar file to a Unix machine. Then I set the class path as below:
    export CLASSPATH=$CLASSPATH:/home.../mail.jar
    Then I tried to compile my Java program. The output is as below:
    error: error reading /home.../mail.jar; invalid END header (bad central directory offset)
    mail.java:1: package javax.mail does not exist
    import javax.mail.*;
    Can any one please help me out.

    You should also include the "activation.jar" file that you obtained from
    downloading the Java Activation Framework, in your CLASSPATH.
    For example:
    export CLASSPATH=$CLASSPATH:/urPath/activation/activation.jar
    Besides, assuming you unzipped javamail-1_4_1.zip in home/download the following should work
    export CLASSPATH=$CLASSPATH:home/download/javamail-1.4.1/mail.jar:.

  • Unable to connect to the Exchange server using HTTP/HTTPS protocol.

    hi,
    i try to connect microsoft exchange server, but it give me
    error
    Unable to connect to the Exchange server using HTTP/HTTPS
    protocol.
    my code is pasted below............
    <!--- connection parameters --->
    <cfparam name="user1" default="uHRH">
    <cfparam name="user2" default="uHRH">
    <cfparam name="password" default="uHRH">
    <cfparam name="exchangeServerIP" default="192.168.0.1">
    <cftry>
    <!--- Open a connection to the exchange server by
    specifying the required user credentials --->
    <cfexchangeConnection
    action="open"
    username ="#user1#"
    password="#password#"
    server="#exchangeServerIP#"
    <!--- protocol = "http"--->
    connection="conn1">
    <cfoutput>Connection to exchange server
    "#exchangeServerIP#" established</cfoutput>
    <!--- Close connection to exchange server --->
    <CFExchangeConnection
    action="close"
    connection="conn1">
    <cfoutput>Connection to exchange server
    "#exchangeServerIP#" terminated</cfoutput>
    <!--- Error Information --->
    <cfcatch type="any">
    <cfoutput>#cfcatch.message#</cfoutput>
    </cfcatch>
    </cftry>
    if any one know how to solve this error?

    Hi,
    The "<cfexchangeConnection>" tag supports both "HTTP"
    and "HTTPS" connection.. So Please make sure the username has the
    "Outlook Web Access".
    Also try removing the <!--- protocol = "http"--->
    comment which you placed inside the "<cfexchangeConnection>"
    tag.

  • Resources for implementing HTTP web server using java

    hi ,
    Thanks for giving your precious time in reading the message.I want to build a HTTP web server using java,which will run on my machine and I can communicate with it through web browser(IE) using HTTP requests and response.
    I know java language, but quite new to network programming.I want to gain enough knowledge on network programming in java.Can you please suggest me good books or any other resources available on the internet for the required subject.Any help will be greatly appreciated.
    my email-id is : [email protected]

    hi there my friend,
    I am writing my own web server too. in w3c there is a sample web server called jigsaw-open source :) and simple-
    I do think it worth trying.
    you can contact me if you want to share some source and info. cause I will.
    [email protected]
    but within 2 weeks I will be back for studying for my web server. you have to wait for a while.

  • How do i connect to sql server using java?

    hi ever body
    i need to connect to sql server using java
    what is the driver i will use?
    thanks

    Microsoft make a jdbc driver and it is readily available through MSDN. Here is a link http://msdn2.microsoft.com/en-us/data/aa937724.aspx. Whatever jdbc driver you are looking for, Google it, and if it exists you'll find it in 10 seconds.

  • I tried to share a photo using e-mail and when I set up my gmail account I typed in the wrong user name and password.  Now i can't share photos using e-mail.

    I tried to share a photo using e-mail and when i set up my gmail account I typed in the wrong user name and password.
    Now I can't send a photo because i get an error message saying the user name and password do not match.
    How do i save a new gmail user name and password??

    iPhoto Menu ->
    Preferences ->
    Accounts ->
    Delete and recreate your email settings.
    Alternatively, use Apple's Mail for the job. It has Templates too - and more of them.

  • How can I authenticate to a XI server using java via SOAP (SAAJ)

    Hi everybody!
    I need to connect (SOAP) to a XI server using JAVA
    I'm using SAAJ api.The problem is XI server need authentication but I can't found the way to do it! this is a part of code
    SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnFactory.createConnection();
    URL destination = new URL("https://host:port");
    SOAPMessage reply = connection.call(message, destination);
    (message is the XML code)
    but the application has the following error:
    com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection post
    GRAVE: SAAJ0009: Fallo en el envío del mensaje
    I think, maybe is a authentication problem, because the XI server needs it. But I don't have idea how can I send the user and pass
    Any IDea???? please
    the libraries are ok imported, I use netweaver to develop-
    thanks in advantage

    hi Leslie,
    there are only a few of these errors,
    you can try this:
    http://www.oxygenxml.com/forum/ftopic1103.html&sid=0abee8c719481a3dd783ff7d5cd84105
    are you sure your URL is accessible from your location?
    you may also check:
    http://www.google.pl/search?hl=pl&q=HttpSOAPConnectionpostSAAJ0009%3A&lr=
    Regards,
    michal

  • Add a posixaccount user in posixgroup in sun directory server using java

    Hi
    Anybody now how to add posixaccount user in posixgroup in sun directory server using java code.
    I am able to add normal directory server user in ldap group in java.
    But i am getting any luck to add posixaccount user in posixgroup.
    I know we can set uid value in memberuid attribute but how to add through java program.
    Anybody can paste code for that.
    Thanks.

    To CRabel,
    My company have restriction on using the open sources product/code, but i will take a look on netscape ldap sdk as a reference~
    To raghu1978 ,
    i find a product call Directory Editor 1 2005Q1, I hope it is useful.
    thz all~

  • Connectiong to Exchange Server through JAVA

    Hi friends,
    I am new to java mail.i have a problem with connecting to exchange server thru java. my java program sends a mail.but i want to get an alert when ever received a mail and also download the mail to local disk from exchange server.
    so if you can please help me.Reply to this ,send me the links or sample codes / paste here itself.
    Advance Thanks,
    Sankar.P

    Hi friends,
    I am new to java mail.i have a problem with connecting to exchange server thru java. my java program sends a mail.but i want to get an alert when ever received a mail and also download the mail to local disk from exchange server.
    so if you can please help me.Reply to this ,send me the links or sample codes / paste here itself.
    Advance Thanks,
    Sankar.P

  • Error of using Java Mail in Web Start

    Hi,
    I got a problem when using Java Mail to send email. My apps is a stand alone and no problem when it was deployed normally. When I used the Web Start to deploy it, the following error was caught when I tried to send email:
    javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary="----=_Part_0_2824645.1032281188963"
         at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:851)
         at javax.activation.DataHandler.writeTo(DataHandler.java:305)
         at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1089)
         at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1527)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:321)
         at javax.mail.Transport.send0(Transport.java:164)
         at javax.mail.Transport.send(Transport.java:81)
         at com.mailcom.client.util.EMail.sendMail(EMail.java:180)
    Here is the source code:
    public class EMail {
    public static void sendMail(String host,
    String sender,
    String recipient,
    String subject,
    String content,
    Vector fileNames) throws MessagingException {
    Properties props = new Properties();
    props.put("mail.smtp.host",host);
    Session session = Session.getDefaultInstance(props,null);
    session.setDebug(true);
    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(sender));
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient,false));
    msg.setSubject(subject);
    Multipart mp = new MimeMultipart();
         // create and fill the first message part
         MimeBodyPart mbp1 = new MimeBodyPart();
         mbp1.setText(content);
         mp.addBodyPart(mbp1);
    // attach the file to the message
    if(fileNames != null && fileNames.size() != 0) {
    FileDataSource fds = null;
    for(int i = 0; i < fileNames.size(); i++ ) {
    String currentFileName = (String)fileNames.elementAt(i);
         fds = new FileDataSource(currentFileName);
         // create the second message part
         MimeBodyPart mbp2 = new MimeBodyPart();
         mbp2.setDataHandler(new DataHandler(fds));
         mbp2.setFileName(fds.getName());
         // create the Multipart and its parts to it
         mp.addBodyPart(mbp2);
         // add the Multipart to the message
         msg.setContent(mp);
    msg.setHeader("X-Mailer",MAILER);
         // set the Date: header
         msg.setSentDate(new Date());
         // send the message
    line 180     Transport.send(msg);

    Yes. All the third party jar files and our application jar are put on the server side. Here is the JNLP file:
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for software-->
    <jnlp spec="1.0+" codebase="http://www.software.com/apps" href="client.JNLP">
    <information>
    <title>client application</title>
    <vendor> * </vendor>
    <homepage href="docs/help.html"/>
    <description>Client</description>
    <description kind="short">A tool</description>
    <icon href="images/logo.jpg"/>
    <offline-allowed/>
    </information>
    <security>
    <all-permissions/>
    </security>
    <resources>
    <j2se version="1.3"/>
    <jar href="lib/client.jar"/>
    <jar href="lib/mail.jar"/>
    <jar href="lib/smtp.jar"/>
    <jar href="lib/activation.jar"/>
    </resources>
    <application-desc main-class="com.software.client.MainFrame">
         <argument>2226</argument>
         <argument>www.software.com</argument>
         <argument>5351</argument>
    </application>
    </jnlp>

  • Problem using Java Mail API with WLS 7.0

    Hi All,
    I am trying to use the Java Mail API provided by WLS 7.0. I have made the
    settings metioned in the WLS 7.0 docs. However when I try to run the program I
    am getting the following error:
    javax.naming.NoInitialContextException: Need to specify class name in environment
    or system property, or as an applet parameter, or in an application resource file:
    java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
    46)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
    a:283)
    at javax.naming.InitialContext.lookup(InitialContext.java:350)
    The code that I have written is as follows
    import java.util.*;
    import javax.activation.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.naming.*;
    import java.io.*;
    import java.net.InetAddress;
    import java.util.Properties;
    import java.util.Date;
    public class MailTo {
         public static void main(String args[])
              try
                   //Context ic = getInitialContext();
                   InitialContext ic = new InitialContext();
    /* My jndi name is "testSession" */
                   Session session = (Session) ic.lookup("testSession"); /* THE PROBLEM IS SHOWN
    IN THIS LINE */
                   Properties props = new Properties();
                   props.put("mail.transport.protocol", "smtp");
                   props.put("mail.smtp.host", "XX.XX.XX.XX");
    /* For security reasons I have written the ip add in this format */
                   props.put("mail.from", "[email protected]"); /* for security reasons i have
    changed the mail address */
                   Session session2 = session.getInstance(props);
                   Message msg = new MimeMessage(session2);
                   msg.setFrom();
                   msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]",
    false));
                   msg.setSubject("Test Message");
                   msg.setSentDate(new Date());
                   MimeBodyPart mbp = new MimeBodyPart();
                   mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
                   Multipart mp = new MimeMultipart();
                   mp.addBodyPart(mbp);
                   msg.setContent(mp);
                   Transport.send(msg);
              catch(Exception e)
                   e.printStackTrace();
         }//end of main
    public static Context getInitialContext()
         throws NamingException
              Properties p = new Properties();
              p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
              p.put(Context.PROVIDER_URL, "t3://localhost:7501/testWebApp");
                   p.put(Context.SECURITY_PRINCIPAL, "weblogic");
                   p.put(Context.SECURITY_CREDENTIALS, "weblogic");
              return new InitialContext(p);
    }//end of class
    Can anyone please tell me what is the problem. I thought that we cannot directly
    do
    InitialContext ic = new InitialContext();
    So I had written a method getInitialContext() as shown in the above piece of code,
    but that too did not work.
    Eagerly awaiting a response.
    Jimmy Shah

    You can use InitialContext ic = new InitialContext() only if you are using a startup class, servlet or a JSP i.e
    server side code.
    If you are using a java client you need to use Context ic = getInitialContext();
    Try this code
    import java.util.*;
    import javax.activation.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.naming.*;
    import java.io.*;
    import java.net.InetAddress;
    import java.util.Properties;
    import java.util.Date;
    public class MailTo {
    public static void main(String args[])
    try {
    Properties h = new Properties();
    h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    h.put(Context.PROVIDER_URL, "t3://localhost:7001");
    Context ic = new InitialContext(h);
    Session session = (Session) ic.lookup("testSession");
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host", "XX.XX.XX.XX");
    props.put("mail.from", "[email protected]");
    Session session2 = session.getInstance(props);
    Message msg = new MimeMessage(session2);
    msg.setFrom();
    msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("[email protected]",false));
    msg.setSubject("Test Message");
    msg.setSentDate(new Date());
    MimeBodyPart mbp = new MimeBodyPart();
    mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp);
    msg.setContent(mp);
    Transport.send(msg);
    catch(Exception e)
    e.printStackTrace();
    }//end of main
    }//end of class
    We have shipped a javamail example in the samples\server\src\examples\javamail folder.
    Jimmy Shah wrote:
    Hi All,
    I am trying to use the Java Mail API provided by WLS 7.0. I have made the
    settings metioned in the WLS 7.0 docs. However when I try to run the program I
    am getting the following error:
    javax.naming.NoInitialContextException: Need to specify class name in environment
    or system property, or as an applet parameter, or in an application resource file:
    java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
    46)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
    a:283)
    at javax.naming.InitialContext.lookup(InitialContext.java:350)
    The code that I have written is as follows
    import java.util.*;
    import javax.activation.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.naming.*;
    import java.io.*;
    import java.net.InetAddress;
    import java.util.Properties;
    import java.util.Date;
    public class MailTo {
    public static void main(String args[])
    try
    //Context ic = getInitialContext();
    InitialContext ic = new InitialContext();
    /* My jndi name is "testSession" */
    Session session = (Session) ic.lookup("testSession"); /* THE PROBLEM IS SHOWN
    IN THIS LINE */
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host", "XX.XX.XX.XX");
    /* For security reasons I have written the ip add in this format */
    props.put("mail.from", "[email protected]"); /* for security reasons i have
    changed the mail address */
    Session session2 = session.getInstance(props);
    Message msg = new MimeMessage(session2);
    msg.setFrom();
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]",
    false));
    msg.setSubject("Test Message");
    msg.setSentDate(new Date());
    MimeBodyPart mbp = new MimeBodyPart();
    mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp);
    msg.setContent(mp);
    Transport.send(msg);
    catch(Exception e)
    e.printStackTrace();
    }//end of main
    public static Context getInitialContext()
    throws NamingException
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, "t3://localhost:7501/testWebApp");
    p.put(Context.SECURITY_PRINCIPAL, "weblogic");
    p.put(Context.SECURITY_CREDENTIALS, "weblogic");
    return new InitialContext(p);
    }//end of class
    Can anyone please tell me what is the problem. I thought that we cannot directly
    do
    InitialContext ic = new InitialContext();
    So I had written a method getInitialContext() as shown in the above piece of code,
    but that too did not work.
    Eagerly awaiting a response.
    Jimmy Shah--
    Rajesh Mirchandani
    Developer Relations Engineer
    BEA Support

  • How to delete message from the fodler of  AOL account using Java mail

    Hello All,
    I am using Java MAil API in my application, i want to delete message from AOL account's folder,
    when i set the folder as "Recently Deleted" or "Trash" , i get an exception as "folder does not exist".
    when i tested , some times mail is moving into Recently Deleted folder, but not every time.
    this is happening in both the interface as AOl Interface or my application.
    when i use folder.close(true) after setting the flag of message as DELETED. it completely remove the message from the acount.
    but i want to let the message be remained in the Recently Deleted folder. what should i do.
    i dont want to remove the message completely from the account.I am using IMAP also.

    You'll need to figure out what the real name of the "Recently Deleted" folder is on the AOL IMAP server
    (assuming it's a real folder and not some sort of "virtual" folder), then copy the message into that folder.
    See the folderlist.java demo program as a way to explore the names of all the folders on the server.

  • Using Java Mail API from Tomcat

    Hello,
    Purely as an academic exercise I have written a JSP page which, upon being requested from the client's browser, should send me a default email using Java Mail Api.
    here is the code :
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class TestMail {
        static String msgText1 = "success this time 12";
        static String msgText2 = "This is the text in the message attachment.";
        public String sendIt() {
            String to = "<my email";
            String from = "<anything>";
            String host = "<my ip address of smtp server>";
            boolean debug = false;
            Properties props = new Properties();
            props.put("mail.smtp.host", host);
            Session session = Session.getInstance(props, null);
    .....The code works fine as a stand alone app but when called from JSP page it hangs on the Session.getInstance line. I can only guess that this might be a security issue with the container not allowing access to the smtp server ?
    Can anyone give me a clue ???

    Your Tomcat log files should spell out the problem for you.
    My Tomcat installation does not come with the Java Mail API. I had to add the mail and activation jar files to the server/common.lib directory (or the server's shared/lib or the WEB-INF/lib of your application.)
    HTH.

Maybe you are looking for

  • Safary crashing!

    hi everybody i just updated my osX to yosemite in  2 weeks now today i just install an application (android emulator) , when it was downloading safari started to crashing and not opened yet the error : Process:           Safari [970] Path:           

  • Cannot mount storage disk after running "reboot -- -r"

    I have a server installed Solaris Sparc u4 and integrated with a storage. When executing "reboot -- -r" or "init 6", the storage disk cannot be mounted after system startup again. The output of console said " obtaining access to all attached disks mo

  • Need admin contact info

    Hello Folks, Sorry to post this here but in this part of the forum i'm used to people knowing what they're talking about and being quick on the response. I've just posted this in a Discussions feedback area: http://discussions.apple.com/thread.jspa?t

  • Please help solve: iPhoto freezes with  pinning wheel

    How can I restore the iPhoto as it is suppose to work. iPhoto would load up to where photos begin to line up but no father with continuous spinning wheel/mouse without normal function within the window(iPhoto). Is it possible reinstall new iPhoto and

  • Can't get stage from a constructor method. Why?

    Hi, I'm making a kind of image showcase, what has a fluid width and height, depending on browser window dimensions. Everything is okay, I have other kind of issue: in constructor function in this gallery class I can't use stage property, I have to ge