hi,
I am writing a "send email" application.
please pleas help me, i strugling whole day ...but could not get a solution...
There is an html page, when click on submit it calls a jsp page that sends a email. Jsp page is using a JavaBean.
When i am running it, it gives me this error.
Sending failed; nested exception is: class javax.mail.MessagingException: Exception reading response; nested exception is: java.net.SocketException: Connection reset
My bean class is:-
package mymail;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
public final class MailerBean extends Object implements Serializable {
private String to =null;
private String from= null;
private String subject = null;
private String message = null;
public static Properties props = null;
public static Session session = null;
static {
props = System.getProperties();
props.put("mail.stmp.host","localhost");
session = Session.getDefaultInstance(props, null);
}
public void setTo(String to) {
this.to = to;
}
public void setFrom(String from) {
this.from = from;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setMessage(String message) {
this.message = message;
}
public void sendMail() throws Exception {
if(!this.everythingIsSet())
throw new Exception("could not send mail.");
try {
MimeMessage message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO,new InternetAddress(this.to));
message.setFrom(new InternetAddress(this.from));
message.setSubject(this.subject);
message.setText(this.message);
Transport.send(message);
}
catch (MessagingException e) {
System.out.println("I can not send the mail" + e.getMessage());
throw new Exception(e.getMessage());
}
}
private boolean everythingIsSet(){
if(this.to == null || this.from == null)
return false;
if((this.to.indexOf("@")==-1) || (this.to.indexOf(".") == -1))
return false;
if((this.from.indexOf("@") == -1) || (this.from.indexOf(".")== -1))
return false;
return true;
}
}
Thanks
Eva


Reply With Quote
Bookmarks