Java Mail...! Experts U have some work here

I am trying send mail from gmail account using the code below.
I have add mail.jar to my classpath, now the problem is my code
is successfully compiled, but generates a runtime error as below.
Any Experts.............??
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
public class SendMailUsingAuthentication
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_AUTH_USER = "sss.sankar";
private static final String SMTP_AUTH_PWD = "*****";
private static final String emailMsgTxt = "Online Order ";
private static final String emailSubjectTxt = "Order Confirmation";
private static final String emailFromAddress = "[email protected]";
private static final String[] emailList = {"[email protected]"};
public static void main(String args[]) throws Exception
SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt,emailFromAddress);
System.out.println("Sucessfully Sent mail to All Users");
public void postMail( String recipients[ ], String subject,String message , String from) throws MessagingException
boolean debug = false;
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
private class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
Error
=====
deps-jar:
Compiling 1 source file to C:\Documents and Settings\promise main\My Documents\NetBeansProjects\sankardemo\build\classes
compile-single:
run-single:
Exception in thread "main" javax.mail.MessagingException: Unknown SMTP host: smtp.gmail.com;
nested exception is:
java.net.UnknownHostException: smtp.gmail.com
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1389)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
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 javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:52)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:20)
Caused by: java.net.UnknownHostException: smtp.gmail.com
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
... 8 more
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)

MSSL wrote:
ya guy i understand that, but any idea about how to correct the same.Give it an smtp host that is reachable.
My guess is that you'll need to go through a proxy server, since I can rech that host just fine.
Or perhaps your DNS is boned.

Similar Messages

  • Somehow my wife has ended up with some of my apps on her iPhone, and I have some of her apps on my iPhone.  So, when I update apps on my phone, some of them ask me for her apple ID password. How do I get her apps off my phone.

    Somehow my wife has ended up with some of my apps on her iPhone, and I have some of her apps on my iPhone.  So, when I update apps on my phone, some of them ask me for her apple ID password. How do I get her apps off my phone.

    Do you guys use the same computer with itunes on it? And the best way to get them off is to go into the Setting>Itunes & App Store and sign out of her appleid if it's listed there. Also just delete all of the apps from her appleid off your phone.

  • First Java Mail Program...some problems

    Hi Friends,
    I am new to JavaMail and i am trying to follow the following exercise:
    http://java.sun.com/developer/onlineTraining/JavaMail/exercises/MailSetup/
    I am using rogers high speed internet connection,so i enter the following:
    D:\JAVAWORLD\javamail1.3.2-src\src\share\classes\demo>java msgsend -o [email protected] -M smtp.broadband.rogers.com [email protected]
    To: [email protected]
    Subject: hi
    Welcome
    ^ZI get the following error:
    com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required - for hel
    p go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
            at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
    275)
            at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
            at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
            at javax.mail.Transport.send0(Transport.java:151)
            at javax.mail.Transport.send(Transport.java:80)
            at msgsend.main(msgsend.java:165)When i went to that yahoo link for help,there are no settings for command line.Please tell me how to accomplish this..friends

    Thanks Ananda,
    But i guess,i should be able to access the rogers smtp server,because i have them as my isp.Moreover,it works fine with my outlook too.I even tried to use a free smtp server called "dumbster",i downladed it but i dont know how to use it.If anyone has some idea,please let me know.
    Thanks

  • IPad mini (and iPhones) says no mail when I have some on home computer

    I suddenly can not get mail on iPad mini or iPhone- says no mail when I actually have mail on my iMac.  Also don't seem to be able to send.  This has all worked before a few days ago.

    Hello nlind,
    Thank you for contacting Apple Support Communities.
    The following article should help you troubleshoot the mail issues on your iOS devices:
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/TS3899
    Regards,
    Jeff D.

  • I have MacBook 10.68.  Yesterday I downloaded the Apple version of Java which I must have to work remotely and now I get the message,"blocked plug in".  Any thoughts?  I cannot access website content any more

    I have MacBook 10.68.  Yesterday I downloaded the Apple version of Java for my system because my company requires it to work remotely but now I cannot access the content on various websites.  I get the message, "blocked plug in".  Any advice?  Thank you.

  • Hi experts i have some while generate purchase,sales and inventry flows

    hai,
           as usual i am using general purchase,sales flow for purchase,sell items to customer and vendor.but its not my issue.the main issue is when i purchase item from vendor i pay some amount to vendor.like this issue when i sell goods to customer i am getting some amount from customer.but whatever amount i am getting from customer and pay to vendor its not hit proper account and its shows negative symbol.
    for example:
             this is my flow for purchasing item
    purchase order------ goods receipt po-- a/p invoicedamaged goods after pay amount-- credit memo
            this is my sales flow
    sales order-- delivery--
    a/r invoice
    while i am doing this process the account whatever generates shows negative sign. its not properly hit specific account.
    plz can u solve this pblm and reply about appropriate account

    Hi,
    you should have a lock under :
    Administration -> Setup -> Financial -> G/L Account
    Under tab purchase and sales you might assign the same g/l accounts for receivable and payable accounts. You should check all accounts, if they are correct.
    Regards Steffen

  • My POP email on both Mail and Outlook have stopped working.

    I can get the mail on a Windows PC with Outlook. Any ideas?
    Thank you.

    Thanks Demo, I appreciate your suggestion. Yours was the one idea not covered in this apple support doc
    and is the one that worked. Thank you.
    Yeah, 'odd' would be an understatement.

  • Hi experts i have some doughts

    i have loaded data into data targets but i want to load data to a particular 0MATERIAL object is it possible or not? if yes how ?if no why?

    Hi,
    Add that particular field in the datasource and replicate the datasource in BW too, so that the changes to the structure also get reflected. Then you can go about loading the data again. I guess you got the point.
    Regards,
    Kishore

  • Basic questions on Java Mail

    Hi,
    I am new to Java Mail and I have following questions. When I send any e-mail with Java Mail through my program it is underlivered if subject length is more. I am yet to discover the limit (in terms of characters) which can be set, but before that I just thaught to take opinion of some of the experts through this forum.
    a) Is there a limitation in subject length in terms of characters?
    b) Can length be increased or is it a problem in the email API or on SMTP server?
    c) How can we pass special characters?
    If anyone can answer it would be great!
    Regards,
    ParagJ

    Hi bshannon,
    Thanks for the reply.
    What's an example "long" subject length that doesn't work? -- If subject length is more than 256 characters the mail is undelivered and I don't get any exception as well. This is the problem with SMTP configuration. I just checked RFC 821 and it says about these size limitations.
    Can we increase this size by somehow changing the SMTP configuration? I have no idea about how to achieve that. I have searched on Google also but didn't get any useful information. If you can focus some light on this I will be thankful to you :).
    Regards,
    ParagJ

  • Need Some Help Here From The Pros....

    Hi all...Im new here you see. I have some questions here..
    1) May I ask if anyone could just tell me how to actually create a partition like Windows do in Mac OS? I need the partition to do my backups and save some of my important documents.
    2) Can we actually create a password to secure certain of my files so that anyone wants to browse it will have to enter the password? Is it possible to do that?
    3) Im also trying to use Visor(i cant remember the name, it's a software to enable Mac to run windows without the boot camp) but i tried on my friend's Macbook, I cant use the MSN camera function... Anybody have any idea??? Or it's not compatible with the camera built-in.
    4) I want to use "3D Studio Max", its it compatible with Mac OS??? and will it be laggish if i uses macbook 13" white?
    Please help....

    Hi!
    1) May I ask if anyone could just tell me how to actually create a partition like Windows do in Mac OS? I need the partition to do my backups and save some of my important documents.
    With your external drive attached, open Disk Utility, found in Applications/Utilities. Choose your drive on the left, and use the Partition tab to set up the number and type of partitions. Partitioning will delete all data on the drive.
    2) Can we actually create a password to secure certain of my files so that anyone wants to browse it will have to enter the password? Is it possible to do that?
    Don't forget that the Mac, just like Windows, is multi-user. You can set up a user for yourself and one for guests or specific people. Nobody can see anybody else's files. You can lock your computer when you go away from the desk if you want absolute privacy.
    Or, you can create an encrypted disk image (also using Disk Utility) to store private files if you really want to stick with one user account.
    3) Im also trying to use Visor(i cant remember the name, it's a software to enable Mac to run windows without the boot camp) but i tried on my friend's Macbook, I cant use the MSN camera function... Anybody have any idea??? Or it's not compatible with the camera built-in.
    Do you mean VMWare Fusion? I believe iSight support is included in the VMWare Tools - when you're running Fusion, there's a menu option to install/update those tools.
    4) I want to use "3D Studio Max", its it compatible with Mac OS??? and will it be laggish if i uses macbook 13" white?
    I believe it's Mac only, so you should check the Windows specs (RAM requirements, graphic card VRAM, etc) to see if you can run it within a virtual Windows on your Macbook.
    Matt

  • IMAP java mail -- Can't disable plain login

    Hi,
    I am trying to solve Authentication issue with IMAP and java mail1.4.1 connecting to Microsoft Exchange Server 2007 and couldn't disable AUTH: PLAIN.Also need to know how to enable NTLM.
    I set the property as follows with "xxxxxxxx...." shown below with right values:
    props.setProperty("mail.store.protocol","imaps");
    props.setProperty("mail.imap.auth.plain.disable","true"); -- "true" within quotes
    props.setProperty("mail.imap.host","xxxxxxxxxxx");
    props.setProperty("mail.imap.port","993");
    props.setProperty("mail.imap.user","xxxxxxx");
    props.setProperty("mail.imap.pwd","xxxxxx");
    props.setProperty("mail.imap.debug","true");
    props.setProperty("mail.imap.ssl.protocols","SSL");
    props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.setProperty("mail.imap.socketFactory.fallback", "false");
    props.setProperty("mail.imap.socketFactory.port", "993");
    Still i couldn't get AUTH:PLAIN disabled and trying to get AUTH:NTLM enabled.
    DEBUG: setDebug: JavaMail version 1.4.1
    DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
    DEBUG: mail.imap.fetchsize: 16384
    * OK Microsoft Exchange Server 2007 IMAP4 service ready
    A0 CAPABILITY
    * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN IDLE NAMESPACE LITERAL+
    A0 OK CAPABILITY completed.
    IMAP DEBUG: AUTH: NTLM
    IMAP DEBUG: AUTH: GSSAPI
    IMAP DEBUG: AUTH: PLAIN
    DEBUG: protocolConnect login, host=xxxxxxxxxxx, user=xxxxxxx, password=<non-null>
    A1 AUTHENTICATE PLAIN
    +
    NzM0NjE1NTk5NAA3MzQ2MTU1OTk0AE5ld3Bhc3N3MHJk
    A1 NO AUTHENTICATE failed.
    caught exception: javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
    javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:566)
    at javax.mail.Service.connect(Service.java:288)
    at javax.mail.Service.connect(Service.java:169)
    at edu.umich.mais.mail.testssl.main(testssl.java:59)
    Please help!!! thanks in advance.

    Hi,
    NTLM is not supported by Java Mail , i am wondering how my previous Java mail 1.3.3 program worked with other mail server (not microsoft exchange server) and produced the following result which seemed to use AUTH=NTLM:
    * OK IMAP4rev1 UMSG-WEB03.UMSG.xxxxx.umich.edu CTI2 interceptor 3.500016100 Service 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
    A1 LOGIN xxxxx xxxxxxx
    A1 OK LOGIN completed.
    A2 LIST "" INBOX
    * LIST (\Marked \HasNoChildren) "/" INBOX
    A2 OK LIST completed.
    DEBUG: connection available -- size: 1
    A3 EXAMINE INBOX
    The IMAP4 capability of exchange server 2007 supporting AUTH mechanisms are as follows --
    A0 CAPABILITY
    * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN IDLE NAMESPACE LITERAL+
    A0 OK CAPABILITY completed.
    IMAP DEBUG: AUTH: NTLM
    IMAP DEBUG: AUTH: GSSAPI
    IMAP DEBUG: AUTH: PLAIN
    If NTLM doesn't work with java mail , any other suggestions to make it work ??
    Thanks

  • My visual voice mail is not working..i have done all the steps that I have seen on here to do. When I call the voice mail it says that there is not a box set up and I need to contact my system administrator.

    My visual voice mail is not working..i have done all the steps that I have seen on here to do. When I call the voice mail it says that there is not a box set up and I need to contact my system administrator.

    I have had voice mail set up on my phone for 10 years. When I did the last iOS update before 7 I guess it wiped out my voice mail. Can I not set it up myself? I haven't changed my message in years.

  • Complete working code for Gmail POP3 & SMTP with SSL - Java mail API

    Finally, your code-hunt has come to an end!!!!
    I am presenting you the complete solution (with code) to send and retrieve you mails to & from GMAIL using SMTP and POP3 with SSL & Authenticaion enabled. [Even starters & newbies like me, can easy try, test & understand - But first download & add JAR's of Java Mail API & Java Activation Framework to Netbeans Library Manager]
    Download Java Mail API here
    http://java.sun.com/products/javamail/
    Read Java Mail FAQ's here
    http://java.sun.com/products/javamail/FAQ.html
    Download Java Activation Framework [JAF]
    http://java.sun.com/products/javabeans/jaf/downloads/index.html
    Also, The POP program retrieves the mail sent with SMTP program :) [MOST IMPORTANT & LARGELY IN DEMAND]okey.. first things first... all of your thanks goes to the following and not a s@!te to me :)
    hail Java !!
    hail Java mail API !!
    hail Java forums !!
    hail Java-tips.org !!
    hail Netbeans !!
    Thanks to all coders who helped me by getting the code to work in one piece.
    special thanks to "bshannon" - The dude who runs this forum from 97!!I am just as happy as you will be when you execute the below code!! [my 13 hours of tweaking & code hunting has paid off!!]
    Now here it is...I only present you the complete solution!!
    START OF PROGRAM 1
    SENDING A MAIL FROM GMAIL ACCOUNT USING SMTP [STARTTLS (SSL)] PROTOCOL OF JAVA MAIL APINote on Program 1:
    1. In the code below replace USERNAME & PASSWORD with your respective GMAIL account username and its corresponding password!
    2. Use the code to make your Gmail client [jsp/servlets whatever]
    //Mail.java - smtp sending starttls (ssl) authentication enabled
    //1.Open a new Java class in netbeans (default package of the project) and name it as "Mail.java"
    //2.Copy paste the entire code below and save it.
    //3.Right click on the file name in the left side panel and click "compile" then click "Run"
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    public class Main
        String  d_email = "[email protected]",
                d_password = "PASSWORD",
                d_host = "smtp.gmail.com",
                d_port  = "465",
                m_to = "[email protected]",
                m_subject = "Testing",
                m_text = "Hey, this is the testing email.";
        public Main()
            Properties props = new Properties();
            props.put("mail.smtp.user", d_email);
            props.put("mail.smtp.host", d_host);
            props.put("mail.smtp.port", d_port);
            props.put("mail.smtp.starttls.enable","true");
            props.put("mail.smtp.auth", "true");
            //props.put("mail.smtp.debug", "true");
            props.put("mail.smtp.socketFactory.port", d_port);
            props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.socketFactory.fallback", "false");
            SecurityManager security = System.getSecurityManager();
            try
                Authenticator auth = new SMTPAuthenticator();
                Session session = Session.getInstance(props, auth);
                //session.setDebug(true);
                MimeMessage msg = new MimeMessage(session);
                msg.setText(m_text);
                msg.setSubject(m_subject);
                msg.setFrom(new InternetAddress(d_email));
                msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
                Transport.send(msg);
            catch (Exception mex)
                mex.printStackTrace();
        public static void main(String[] args)
            Main blah = new Main();
        private class SMTPAuthenticator extends javax.mail.Authenticator
            public PasswordAuthentication getPasswordAuthentication()
                return new PasswordAuthentication(d_email, d_password);
    END OF PROGRAM 1-----
    START OF PROGRAM 2
    RETRIVE ALL THE MAILS FROM GMAIL INBOX USING Post Office Protocol POP3 [SSL] PROTOCOL OF JAVA MAIL APINote:
    1.Log into your gmail account via webmail [http://mail.google.com/]
    2.Click on "settings" and select "Mail Forwarding & POP3/IMAP"
    3.Select "enable POP for all mail" and "save changes"
    4.In the code below replace USERNAME & PASSWORD with your respective GMAIL account username and its corresponding password!
    PROGRAM 2 - PART 1 - Main.java
    //1.Open a new Java class file in the default package
    //2.Copy paste the below code and rename it to Mail.java
    //3.Compile and execute this code.
    public class Main {
        /** Creates a new instance of Main */
        public Main() {
         * @param args the command line arguments
        public static void main(String[] args) {
            try {
                GmailUtilities gmail = new GmailUtilities();
                gmail.setUserPass("[email protected]", "PASSWORD");
                gmail.connect();
                gmail.openFolder("INBOX");
                int totalMessages = gmail.getMessageCount();
                int newMessages = gmail.getNewMessageCount();
                System.out.println("Total messages = " + totalMessages);
                System.out.println("New messages = " + newMessages);
                System.out.println("-------------------------------");
    //Uncomment the below line to print the body of the message. Remember it will eat-up your bandwidth if you have 100's of messages.            //gmail.printAllMessageEnvelopes();
                gmail.printAllMessages();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(-1);
    END OF PART 1
    PROGRAM 2 - PART 2 - GmailUtilities.java
    //1.Open a new Java class in the project (default package)
    //2.Copy paste the below code
    //3.Compile - Don't execute this[Run]
    import com.sun.mail.pop3.POP3SSLStore;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Date;
    import java.util.Properties;
    import javax.mail.Address;
    import javax.mail.FetchProfile;
    import javax.mail.Flags;
    import javax.mail.Folder;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Multipart;
    import javax.mail.Part;
    import javax.mail.Session;
    import javax.mail.Store;
    import javax.mail.URLName;
    import javax.mail.internet.ContentType;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.ParseException;
    public class GmailUtilities {
        private Session session = null;
        private Store store = null;
        private String username, password;
        private Folder folder;
        public GmailUtilities() {
        public void setUserPass(String username, String password) {
            this.username = username;
            this.password = password;
        public void connect() throws Exception {
            String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
            Properties pop3Props = new Properties();
            pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
            pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
            pop3Props.setProperty("mail.pop3.port",  "995");
            pop3Props.setProperty("mail.pop3.socketFactory.port", "995");
            URLName url = new URLName("pop3", "pop.gmail.com", 995, "",
                    username, password);
            session = Session.getInstance(pop3Props, null);
            store = new POP3SSLStore(session, url);
            store.connect();
        public void openFolder(String folderName) throws Exception {
            // Open the Folder
            folder = store.getDefaultFolder();
            folder = folder.getFolder(folderName);
            if (folder == null) {
                throw new Exception("Invalid folder");
            // try to open read/write and if that fails try read-only
            try {
                folder.open(Folder.READ_WRITE);
            } catch (MessagingException ex) {
                folder.open(Folder.READ_ONLY);
        public void closeFolder() throws Exception {
            folder.close(false);
        public int getMessageCount() throws Exception {
            return folder.getMessageCount();
        public int getNewMessageCount() throws Exception {
            return folder.getNewMessageCount();
        public void disconnect() throws Exception {
            store.close();
        public void printMessage(int messageNo) throws Exception {
            System.out.println("Getting message number: " + messageNo);
            Message m = null;
            try {
                m = folder.getMessage(messageNo);
                dumpPart(m);
            } catch (IndexOutOfBoundsException iex) {
                System.out.println("Message number out of range");
        public void printAllMessageEnvelopes() throws Exception {
            // Attributes & Flags for all messages ..
            Message[] msgs = folder.getMessages();
            // Use a suitable FetchProfile
            FetchProfile fp = new FetchProfile();
            fp.add(FetchProfile.Item.ENVELOPE);       
            folder.fetch(msgs, fp);
            for (int i = 0; i < msgs.length; i++) {
                System.out.println("--------------------------");
                System.out.println("MESSAGE #" + (i + 1) + ":");
                dumpEnvelope(msgs);
    public void printAllMessages() throws Exception {
    // Attributes & Flags for all messages ..
    Message[] msgs = folder.getMessages();
    // Use a suitable FetchProfile
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.ENVELOPE);
    folder.fetch(msgs, fp);
    for (int i = 0; i < msgs.length; i++) {
    System.out.println("--------------------------");
    System.out.println("MESSAGE #" + (i + 1) + ":");
    dumpPart(msgs[i]);
    public static void dumpPart(Part p) throws Exception {
    if (p instanceof Message)
    dumpEnvelope((Message)p);
    String ct = p.getContentType();
    try {
    pr("CONTENT-TYPE: " + (new ContentType(ct)).toString());
    } catch (ParseException pex) {
    pr("BAD CONTENT-TYPE: " + ct);
    * Using isMimeType to determine the content type avoids
    * fetching the actual content data until we need it.
    if (p.isMimeType("text/plain")) {
    pr("This is plain text");
    pr("---------------------------");
    System.out.println((String)p.getContent());
    } else {
    // just a separator
    pr("---------------------------");
    public static void dumpEnvelope(Message m) throws Exception {       
    pr(" ");
    Address[] a;
    // FROM
    if ((a = m.getFrom()) != null) {
    for (int j = 0; j < a.length; j++)
    pr("FROM: " + a[j].toString());
    // TO
    if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
    for (int j = 0; j < a.length; j++) {
    pr("TO: " + a[j].toString());
    // SUBJECT
    pr("SUBJECT: " + m.getSubject());
    // DATE
    Date d = m.getSentDate();
    pr("SendDate: " +
    (d != null ? d.toString() : "UNKNOWN"));
    static String indentStr = " ";
    static int level = 0;
    * Print a, possibly indented, string.
    public static void pr(String s) {
    System.out.print(indentStr.substring(0, level * 2));
    System.out.println(s);
    }END OF PART 2
    END OF PROGRAM 2
    P.S: CHECKING !!
    STEP 1.
    First compile and execute the PROGRAM 1 with your USERNAME & PASSWORD. This will send a mail to your own account.
    STEP 2.
    Now compile both PART 1 & PART 2 of PROGRAM 2. Then, execute PART 1 - Main.java. This will retrive the mail sent in step 1. njoy! :)
    In future, I hope this is added to the demo programs of the Java Mail API download package.
    This is for 3 main reasons...
    1. To prevent a lot of silly questions being posted on this forum [like the ones I did :(].
    2. To give the first time Java Mail user with a real time working example without code modification [code has to use command line args like the demo programs - for instant results].
    3. Also, this is what google has to say..
    "The Gmail Team is committed to making sure you always can access your mail. That's why we're offering POP access and auto-forwarding. Both features are free for all Gmail users and we have no plans to charge for them in the future."
    http://mail.google.com/support/bin/answer.py?answer=13295
    I guess bshannon & Java Mail team is hearing this....
    Again, Hurray and thanks for helping me make it!! cheers & no more frowned faces!!
    (: (: (: (: (: GO JCODERS GO!! :) :) :) :) :)
    codeace
    -----                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    Thanks for the reply,
    I did checked by enabling session debuging and also checked pop settings it's enabled for all
    mails, I tried deleting some very old messages and now the message count is changed to 310.
    This may be the problem with gmail.
    Bellow is the output i got,
    DEBUG: setDebug: JavaMail version 1.4ea
    DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
    DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL false
    S: +OK Gpop ready for requests from 121.243.255.240 n22pf5432603pof.2
    C: USER [email protected]
    S: +OK send PASS
    C: PASS my_password
    S: +OK Welcome.
    C: STAT
    S: +OK 310 26900234
    Custom output: messageCount : 310
    C: QUIT
    S: +OK Farewell.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • My new iphone 4  wont power on does the battery have to charge first? It was shipped thru mail and took 7days to get here.I managed to turn it on once and shut it of because i had to put sim card in.Now it wont power on.

    I tried holding down both buttons like everyone said and this doesnt work. My phone was shipped new from Ontario to Sask and took about a week to get here,Could it be because my battery is so low? And shouldnt it power on when it's plugged in or show a phone charging icon or have some lite on? My laptop won't even discover it when I plug it in. When I first took it out of the box i called virgin mobile.The lady told me to put sim card in because it did turn on at first and was asking for sim card so i put it in and all kinds of languages were displayed so i clicked on english and then then somehow shut the phone off because i wasnt familiar with it yet i have no idea how i shut it off.Anyway, I read a bit further and saw where the power button was and tried to turn it back on. No luck the apple logo appears with what looks like a hairline crack on the apple itself and a very thin blue bar no thicker than a pen stroke its about halfway right behind the apple logo like its going to power on but it doesnt, it just goes black.Then when I hold the 2 buttons down, the home button and the power button at the same time, the apple logo flahes on about every 3or4 seconds as tho its going to turn on but it doesnt, occasionally the bar comes up with the logo but not every time.What can I do? Will it work if I let it charge for a couple hours? Does it need a couple hrs and shud there at least be a charging icon showing me its charging?? I have it hooked up by USB to my laptop charging.My computer and Itunes doesnt even acknowledge its even there. PLEASE HELP? Thanks so much!

    Plug your phone into the wall charger for at least 30 minutes...make sure you have a sim card in the phone...then:
    Leave the USB cable connected to your computer, but NOT your phone, iTunes running, press & hold the home button while connecting the USB cable to your dock connector, continue holding the home button until you see “Connect to iTunes” on the screen. You may now release the home button. iTunes should now display that it has detected your phone in recovery mode, if not quit and reopen iTunes. If you still don’t see the recovery message repeat these steps again. iTunes will give you the option to restore from a backup or set up as new.
    Make sure you have no anti-virus software running or any firewalls...turn all of that stuff off.

  • I uploaded that new IOS 8.0 and now I cannot open my mail, Safari, or the new "TIPS" app. Does Apple have some sort of help, other than going to a store that is over 40 miles away?

    I uploaded that new IOS 8.0 and now I cannot open my mail, Safari, or the new "TIPS" app. Does Apple have some sort of help, other than going to a store that is over 40 miles away?

    Purplehiddledog wrote:
    I do backup with iCloud.  I can't wait until the new iMac is available so that I can once again have my files in more than 1 location without needing to rely solely on the cloud. 
    I also rely on iTunes and my MacBook and Time Machine as well as backing up to iCloud. I know many users know have gone totally PC free, but I chose to use iCloud merely as my third backup.
    I assume that the restore would result in my ability to open Pages and Numbers and fix the problem with deleting apps, but this would also mean that if my Numbers documents still exist solely within the app and are just not on iCloud for some reason that they would be gone forever.  Is that right?
    In a word, yes. In a little more detail.... When you restore from an iCloud backup, you must erase the device and start all over again. There is no other way to access the backup in iCloud without erasing the device. Consequently, you are starting all over again. Therefore, it would also be my assumption that Pages and Numbers will work again and that the deleting apps issues would be fixed as well.
    If the documents are not in the backup, and you do not have a backup elsewhere, the documents could be gone forever.

Maybe you are looking for