Janitha

JAVA NETBEANS TUTORIALS

Wikipedia

Search results

Saturday, October 20, 2012

Java Email Code || using gmail || netbeans

Click Here
Imports....

import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
.......................................................................
Libraries  Download..
Click Here to download .jar files
 ................................................................................................
 ..............code start............................................
try {

            String body=jTextArea1.getText();-- Body
            String email=txtemail.getText();// -- To

                // Using SSL           
            Properties propsSSL = new Properties();
            propsSSL.put("mail.transport.protocol", "smtps");
            propsSSL.put("mail.smtps.host", "smtp.gmail.com");
            propsSSL.put("mail.smtps.auth", "true");

            Session sessionSSL = Session.getInstance(propsSSL);
            sessionSSL.setDebug(true);

            Message messageSSL = new MimeMessage(sessionSSL);
            messageSSL.setFrom(new InternetAddress("youremail@gmail.com", "janitha"));//your email            messageSSL.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); recipient
            messageSSL.setSubject(txtsubject.getText());
            messageSSL.setText(body);

            Transport transportSSL = sessionSSL.getTransport();
            transportSSL.connect("smtp.gmail.com", 465, "youremail@gmail.com", "password");

          // youremail@gmail.com---set your email adress
           //password ---- set email password   
                                
            transportSSL.sendMessage(messageSSL, messageSSL.getAllRecipients());
            transportSSL.close();

            System.out.println("SSL done.");
            System.out.println("------------------------------------Email Send------------------------------------");

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

6 comments:

  1. Thankѕ for finaply talking about > "Java Email Code || using gmail || netbeans" < Loved it!

    Stop by my webpage Homes
    just Liѕted

    ReplyDelete
  2. Hello tο ɑll, how is the whole thing, I think everү onе
    is gettiոg more from this site, and үօur views arre pleasant for neew
    ѵisitors.

    Also visіt mmy wеb site :: luxury homes MN top realtors

    ReplyDelete
  3. What's Taking place i am nnew to this, I stumbled upon this I've discovered It absolutely helpful and it has helped me
    out loads. I am hoping to contribute & assist different users like its aided me.
    Good job.

    Have a look at my homepage: luxury Homes mn

    ReplyDelete
  4. I am regular vіѕitor, how are ʏyou everybοdy? This paragгaph
    posted at this website іs really fastidious.

    Here iѕ my webpaɡe :: san diego homes

    ReplyDelete
  5. Hello very nice site!! Man .. Beautful .. Wonderful .. I'll bookmark your
    blolg and take thee feeds also? I am happy to search out so many useful info
    right here in the pput up, wwe waqnt develop more strategies on this regard, thank
    you for sharing. . . . . .

    Feel free to vissit my web-site downtown toronto condos real Estate listings

    ReplyDelete
  6. Wɦat'ѕ up, this weekend is good in favor of me, for the reason that this time
    i aam reading this impressive educatіonal post here at my house.


    Stop Ƅʏ my site :: legacy luxury homes MN

    ReplyDelete