dcsimg
Why can't I send email in JSP with javamail???
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   fentid_Peng
Posted On:   Friday, April 13, 2001 12:20 AM

I write a javabean to send email with javamail and I can send email successful in this bean's mail function. But I can't send email in the JSP file which call the javabean and display follow Exception: No provider for smtp But I have already set the server of SMTP! My JSP server is Weblogic5.1 Win98 source of javabean SendMail.java //**************************************** package com.hyp.mail; /* * Copyright (c) 2001 HYP.com . All Rights Reserved. * @Author Fentid */ import java.io.*; import java.util.Properties; import java.util.*;    More>>

I write a javabean to send email with javamail

and I can send email successful in this bean's mail function.

But I can't send email in the JSP file which call the javabean

and display follow Exception:
No provider for smtp


But I have already set the server of SMTP!

My JSP server is Weblogic5.1

Win98


source of javabean SendMail.java

//****************************************

package com.hyp.mail;

/*

* Copyright (c) 2001 HYP.com . All Rights Reserved.

* @Author Fentid

*/

import java.io.*;

import java.util.Properties;

import java.util.*;

import com.hyp.util.*;


import javax.mail.*;

import javax.activation.*;

import javax.mail.internet.*;




public class¡¡SendMail

{

private String Host ;

private String From ;

private String FromName;

private String To;

private String ToName;

private String Subject;

private String Body;


private Message msg;


public SendMail()

{
Host = "smtp.263.net";

From = "fentid@263.net";

FromName = "fentid" ;

To = "fentid@wyu.edu.cn";

ToName = "HappyHero";

Subject = "The product information you want!";

Body = "this is a test!";


}


/**

* code function: send the email

*/

public void send() throws Exception

{

// create some properties and get the default Session

¡¡¡¡¡¡¡¡Properties props = new Properties;

¡¡¡¡¡¡¡¡props.put("mail.smtp.host", Host);


¡¡¡¡¡¡¡¡Session session¡¡¡¡= Session.getDefaultInstance(props, null);

¡¡¡¡¡¡¡¡Message message = new MimeMessage(session);


¡¡¡¡¡¡¡¡// create a message

¡¡¡¡¡¡¡¡InternetAddress ia[] = new InternetAddress[1];

¡¡¡¡¡¡¡¡ia[0] = new InternetAddress(To, ToName);


¡¡¡¡¡¡¡¡message.setFrom(new InternetAddress(From, FromName));

¡¡¡¡¡¡¡¡message.setRecipients(Message.RecipientType.TO, ia);

¡¡¡¡¡¡¡¡message.setSubject(Subject);

¡¡¡¡¡¡ // message.setText(Body);

¡¡¡¡collect(message);

message.setSentDate(new Date());


¡¡¡¡¡¡¡¡message.saveChanges();


¡¡¡¡¡¡¡¡Transport transport = session.getTransport("smtp");

¡¡¡¡¡¡¡¡transport.connect();

¡¡¡¡¡¡¡¡transport.send(message);

System.out.println("The email have already been sent!");

}

......

.....

public static void main(String[] args)

{


SendMail sm = new SendMail();

try

{


sm.send();

}

catch(Exception e)

{

System.err.println("Error in main:" + e.getMessage());

}


}

}

//****************************************




//the code in jsp call the javabean

//******************************************

SendMail sm = new SendMail();

try

{

sm.send();

}

catch(Exception e)

{

out.println("Error in Send.jsp:" + e.getMessage()+"
");

}

//**********************************************


in here e.getMessage£¨£©return No provider for smtp

   <<Less
About | Sitemap | Contact