Roy:

Since your class JavaMailer's constructor throws the MessagingException, you
need to enclose the *call* to the constructor:

    jm = new JavaMailer(note, sender);

within a "try/catch" block. Or declare it in the throws clause of the method
*which contains" the above statement.

Regards,
Geeta

roy woods wrote:

> Hi all
>
> I have a class that sends email from servlet and it
> working fine when I use it as a single class it works
> and the mail is sent successfully but when I try to
> create an object of this class to send the message I
> get this: Exception javax.mail.MessagingException must
> be caught or it must be declared in throws clause of
> this method
>
> jm = new JavaMailer(note, sender);
>       ^
> But I already threw the Exception in that constructor.
> what is going on?
>
> Part of the code:
>
>    public JavaMailer(String msgContent, String sender)
> throws MessagingException
>    {
>            this.msgContent = msgContent;
>            this.sender = sender;
>
>     Properties props = new Properties();
>     props.put("mail.smtp.host","keryx.evitech.fi");
>     InternetAddress[] addrs = null;
>     Session session =
> Session.getDefaultInstance(props,null);
>
>     try
>     {
>
>      Message msg = new MimeMessage(session);
>      msg.setHeader("X-Mailer", "JavaMailer");
>      msg.setSentDate(new Date());
>      InternetAddress from = new
> InternetAddress(sender);
>      InternetAddress rcp1 = new
> InternetAddress("[EMAIL PROTECTED]");
>      InternetAddress rcp2 = new
> InternetAddress("[EMAIL PROTECTED]");
>      msg.setFrom(from);
>
>      InternetAddress[] address = { rcp1, rcp2 };
>
> msg.setRecipients(Message.RecipientType.TO,address);
>      msg.setSubject("JavaMail anyone?");
>      msg.setContent(msgContent,"text/plain");
>      msg.setSentDate(new Date());
>      Transport.send(msg);
>      System.out.println("Mail sent successfully");
>     }
>     catch (Exception ex)
>     {
>          System.out.println("Mail not sent. Reason:");
>      ex.printStackTrace();
>     }
>    }
>
> Thanks all
>
> roys
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/?.refer=text
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to