Re: a small correction - Weblogic
This is a discussion on Re: a small correction - Weblogic ; ...
-
Re: a small correction
-
Re: a small correction
Hi,
Did you have find a solution to your probleme? I have the same one.
I have a bean and a jsp very similare to yours.
When i call the send method of my bean from a jsp page i get a java
NullPointerException on the line "new MimeMessage(session)"
So i will inform you i i find something.
Bye
Nicolas PERIDONT
"Shankar Roy" <shankar@careassured.com> a =C3=A9crit dans le message news:
8hm8qt$f61$1@newsgroups.bea.com...
> JSP snippet should be read as follows
>
> <%
>
CMail.send("shankar@careassured.com","shankar@careassured.com","smtp.careas=
s
> ured.com","You have
> been enrolled","You have been enrolled successfully");%>
>
> Shankar Roy <shankar@careassured.com> wrote in message
> news:8hm8ju$f20$1@newsgroups.bea.com...
> > Can't send a mail from jsp?
> > After
> > System.out.println("Test 1");
> > it gives
> > java.lang.NullPointerException
> > at com.careassured.util.CMail.send(CMail.java, Compiled Code)
> > at com.careassured.util.CMail.send(CMail.java:53)
> >
> > Any idea is appreciated
> > Thank in advance,
> > Shankar.
> >
> >
> > JSP snippet
> >
> > <%
>
CMail.send("shankar@careassured.com","shankar@careassured.com","smtp.careas=
s
> ured.com","You have
> > been enrolled","You have been enrolled successfully");%>
> >
> > sendMail code snippet
> >
> > public static void send(String to, String from, String host, String
> subTxt,
> > String msgTxt, boolean debug)
> > {
> > subText =3D subTxt;
> > msgText =3D msgTxt;
> > // create some properties and get the default Session
> > Properties props =3D System.getProperties();
> > System.out.println("Test 1");
> > props.put("mail.smtp.host", host);
> > props.put("mail.transport.protocol", "smtp");
> > props.put("mail.smtp.class", "com.sun.mail.smtp.SMTPTransport");
> > if (debug) props.put("mail.debug", new Boolean(debug));
> > Session session =3D Session.getDefaultInstance(props, new
> CAuthenticator());
> > javax.mail.Session session =3D
> > javax.mail.Session.getDefaultInstance(props, null);
> > session.setDebug(debug);
> > if(session !=3D null)
> > {
> > try
> > {
> > // create a message
> > if(session =3D=3D null) System.out.println(" Sessio=
n is
> null
> > ");
> > System.out.println("Test 1");
> > Message msg =3D new MimeMessage(session);
> > System.out.println("Test 2");
> > msg.setFrom(new InternetAddress(from));
> > InternetAddress[] address =3D {new InternetAddress(to)};
> > msg.setRecipients(Message.RecipientType.TO, address);
> > msg.setSubject(subText);
> > msg.setSentDate(new Date());
> > // If the desired charset is known, you can use
> > // setText(text, charset)
> > msg.setText(msgText);
> > Transport.send(msg);
> > }
> > catch (MessagingException mex)
> > {
> > System.out.println("\n--Exception handling in Mail.java");
> >
> > mex.printStackTrace();
> > System.out.println();
> > Exception ex =3D mex;
> > do
> > {
> > if (ex instanceof SendFailedException)
> > {
> > SendFailedException sfex =3D (SendFailedException)ex;
> > Address[] invalid =3D sfex.getInvalidAddresses();
> > if (invalid !=3D null)
> > {
> > System.out.println(" ** Invalid Addresses");
> > if (invalid !=3D null)
> > {
> > for (int i =3D 0; i < invalid.length; i++)
> > System.out.println(" " + invalid[i]);
> > }
> > }
> >
> > Address[] validUnsent =3D sfex.getValidUnsentAddresses();
> > if (validUnsent !=3D null)
> > {
> > System.out.println(" ** ValidUnsent Addresses");
> > if (validUnsent !=3D null)
> > {
> > for (int i =3D 0; i < validUnsent.length; i++)
> > System.out.println(" "+validUnsent[i]);
> > }
> > }
> >
> > Address[] validSent =3D sfex.getValidSentAddresses();
> > if (validSent !=3D null)
> > {
> > System.out.println(" ** ValidSent Addresses");
> > if (validSent !=3D null)
> > {
> > for (int i =3D 0; i < validSent.length; i++)
> > System.out.println(" "+validSent[i]);
> > }
> > }
> > }
> > System.out.println();
> > }
> > while ((ex =3D ((MessagingException)ex).getNextException()) !=3D nul=
l);
> > }
> > catch(Exception e)
> > {
> > e.printStackTrace();
> > }
> > }
> > else System.out.println(" Session is null");
> > }
> >
> >
> >
>
>