problem sending javamail

N

Nilambari

hi

i am facing a problem for SMTPTransport.openserver......

i am getting following error when i am trying to send email using
javamail servlet:

java.lang.NoSuchMethodError:
com.sun.mail.util.TraceInputStream.setQuote(Z)V
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:956)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:191)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)
at geezmail.makeTable(geezmail.java:169)
at geezmail.doPost(geezmail.java:99)

and the log says invalid protocoll: null

Following is my code for sending email:

Properties props = System.getProperties();
//props.setProperty("mail.host", "cyber");
props.setProperty("mail.smtp.host", "127.0.0.1");
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.port", "25");
props.setProperty("mail.user", "");
props.setProperty("mail.password", "");

Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport("smtp");
//URLName urlname = new URLName("www.geezemail.com");
//com.sun.mail.smtp.SMTPTransport transport = new
com.sun.mail.smtp.SMTPTransport(mailSession, urlname);

MimeMessage message = new MimeMessage(mailSession);
message.setContent(msg, "text/html");
if (from.length() == 0){
return
"<center><table border=0>" +
"<tr>" +
"<td><H2>" + "From: field is not provided." +
"</H2></td>" +
"</tr>" +
"</table></center>";
}
else if (to.length() != 0) {
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
if (cc.length() != 0)
message.addRecipient(Message.RecipientType.CC, new
IernetAddress(cc));
if (bcc.length() != 0)
message.addRecipient(Message.RecipientType.BCC, new
InternetAddress(bcc));
message.setSubject(subject);
InternetAddress reply[] = new InternetAddress[1];
reply[0] = new InternetAddress(from);
message.setReplyTo(reply);
transport.connect("127.0.0.1",25,"","");//169
//message.saveChanges();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();


Can anybody help me?

Nilambari
(e-mail address removed)
 
G

GaryM

(e-mail address removed) (Nilambari) wrote in


Following is my code for sending email:

Properties props = System.getProperties();
//props.setProperty("mail.host", "cyber");
props.setProperty("mail.smtp.host", "127.0.0.1");
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.port", "25");
props.setProperty("mail.user", "");
props.setProperty("mail.password", "");

Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport("smtp");
//URLName urlname = new URLName("www.geezemail.com");
//com.sun.mail.smtp.SMTPTransport transport = new
com.sun.mail.smtp.SMTPTransport(mailSession, urlname);

You dont need the lines above. Is this where you are getting the
exception? You can replace everything with:

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

(note set debug if you like and if the smtp host is going to be other
than localhost you need to set that too.)

MimeMessage message = new MimeMessage(mailSession);
message.setContent(msg, "text/html");
if (from.length() == 0){
return
"<center><table border=0>" +
"<tr>" +
"<td><H2>" + "From: field is not provided." +
"</H2></td>" +
"</tr>" +
"</table></center>";
}
else if (to.length() != 0) {
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
if (cc.length() != 0)
message.addRecipient(Message.RecipientType.CC, new
IernetAddress(cc));
if (bcc.length() != 0)
message.addRecipient(Message.RecipientType.BCC,
new
InternetAddress(bcc));
message.setSubject(subject);
InternetAddress reply[] = new InternetAddress[1];
reply[0] = new InternetAddress(from);
message.setReplyTo(reply);
transport.connect("127.0.0.1",25,"","");//169
//message.saveChanges();


The following 2 lines can be replaced with

Transport.send(message);
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();

<snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top