Problem in Sending mail thru gmail........

i am new to Java mail API,can any one help me out...

i have gmail a/c named ajaypatel1724@gmail.com and it is smtp enabled.

now i want to send mail from my application.so, i write the following code....but it give some error as describe follow.....

/**************** Code **************/

package mailsend;

import java.util.*;

import java.io.*;

import javax.mail.*;

import javax.mail.internet.*;

import javax.activation.*;

Mahesh Dave. 9960497637

public class Main {

static String msgText1 = "This is a message body.\nHere's line two.";

static String msgText2 = "This is the text in the message attachment.";

/** Creates a new instance of Main */

public Main() {

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

String to = "ajaypatel1724@yahoo.com";

String from = "ajaypatel1724@gmail.com";

String host = "smtp.gmail.com";

boolean debug = Boolean.valueOf(false).booleanValue();

// create some properties and get the default Session

Properties props = new Properties();

props.put("mail.smtp.host", host);

Session session = Session.getInstance(props, null);

session.setDebug(debug);

try

{

// create a message

MimeMessage msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

InternetAddress[] address = {new InternetAddress(to)};

msg.setRecipients(Message.RecipientType.TO, address);

msg.setSubject("JavaMail APIs Multipart Test");

msg.setSentDate(new Date());

// create and fill the first message part

MimeBodyPart mbp1 = new MimeBodyPart();

mbp1.setText(msgText1);

// create and fill the second message part

MimeBodyPart mbp2 = new MimeBodyPart();

// Use setText(text, charset), to show it off !

mbp2.setText(msgText2, "us-ascii");

// create the Multipart and its parts to it

Multipart mp = new MimeMultipart();

mp.addBodyPart(mbp1);

mp.addBodyPart(mbp2);

// add the Multipart to the message

msg.setContent(mp);

// send the message

Transport.send(msg);

}

catch (MessagingException mex)

{

mex.printStackTrace();

Exception ex = null;

if ((ex = mex.getNextException()) != null)

{

ex.printStackTrace();

}

}

}

}

/*************** Error **************/

init:

deps-jar:

Compiling 1 source file to C:\Documents and Settings\Administrator\My Documents\MailSend\build\classes

compile:

run:

javax.mail.NoSuchProviderException: smtp

at javax.mail.Session.getService(Session.java:768)

at javax.mail.Session.getTransport(Session.java:708)

at javax.mail.Session.getTransport(Session.java:651)

at javax.mail.Session.getTransport(Session.java:631)

at javax.mail.Session.getTransport(Session.java:686)

at javax.mail.Transport.send0(Transport.java:166)

at javax.mail.Transport.send(Transport.java:98)

at mailsend.Main.main(Main.java:81)

BUILD SUCCESSFUL (total time: 7 seconds)

So can any one help to solve above probs........and also i want to made atachement inform of file.....anyone have any idea about this, can help.....

Thank you in advance.....

[3482 byte] By [Agpatela] at [2007-11-27 0:48:42]
# 1

You've read the JavaMail FAQ, right? If not, please do now.

You've also found and tried the many sample programs that

come with JavaMail, right?

javax.mail.NoSuchProviderException: smtp

This error is often a result of not using mail.jar directly but instead extracting

the classes from mail.jar and adding them to your application. Don't do that.

If that's not what you did, I need more information about your environment,

such as your CLASSPATH setting.

bshannona at 2007-7-11 23:17:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

GMail SMTP does not use the standard port (25), so your code isn't finding the server. I believe Gmail SMTP server uses port 465.

props.put("mail.smtp.port", "465");

Unfortunately, your code still won't work. Gmail SMTP requires you to authenticate before sending mail. Take a look at this thread:

http://forum.java.sun.com/thread.jspa?threadID=668779

MrButtheada at 2007-7-11 23:17:47 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...