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.....

