dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: send mail

  1. #1
    Join Date
    Mar 2006
    Posts
    17

    send mail

    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

  2. #2
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Please don't cross post.
    54 68 65 42 65 61 72 4D 61 79

  3. #3
    Join Date
    Mar 2006
    Posts
    17
    Actually , I did not know where should i be putting this problem? there is nothing for JSP.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles