Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javax.mail problem

Status
Not open for further replies.

relisys

Programmer
Mar 6, 2003
65
GB
Evening guys,

Running a servlet which runs fine. I added a sendEmail method to auto send emails, however when i add this and compile it, Apache bombs out saying file cannot be found.

But when I remove this method the servlet runs normally - any ideas would be appreciated!

=============code follows================

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.util.*;
import java.sql.*;
import java.text.*;

import javax.mail.*;
import javax.mail.internet.*;


/**
* This class deals with booking doctor appointments.
**/

public class ConfirmReferPatient extends AbstractPage{

public void doRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
super.doRequest(request, response);
if (nosession){
return;
}
String patientId = request.getParameter("patientId");
String docId = request.getParameter("docName");
String notes = request.getParameter("notes");

try {
if(patientId.equals("")){
patientId="";
}
} catch (Exception e) {
patientId="";
}

try {
if(docId.equals("")){
docId="";
}
} catch (Exception e) {
docId="";
}

try {
if(notes.equals("")){
notes="";
}
} catch (Exception e) {
notes="";
}


if(patientId.equals("")){

String reason1 = "No Patient Id Entered";

Doctor[] doctors = Doctor.load(con);

Document AddDOM = createDom(doctors, "");
MyXSLProc xslProc = new MyXSLProc();

Element root = AddDOM.getDocumentElement();
Element reason = AddDOM.createElement("reason");
reason.appendChild(AddDOM.createTextNode(reason1));

root.appendChild(reason);

xslProc.process(request, response, "/medicare/ReferPatient.xsl", AddDOM);
return;

}
if(notes.equals("")){

String reason1 = "No Referral Notes Entered";

Doctor[] doctors = Doctor.load(con);

Document AddDOM = createDom(doctors, "");
MyXSLProc xslProc = new MyXSLProc();

Element root = AddDOM.getDocumentElement();
Element reason = AddDOM.createElement("reason");
reason.appendChild(AddDOM.createTextNode(reason1));

root.appendChild(reason);

xslProc.process(request, response, "/medicare/ReferPatient.xsl", AddDOM);
return;

}
if(docId.equals("")){

String reason1 = "No Doctor Selected";

Doctor[] doctors = Doctor.load(con);

Document AddDOM = createDom(doctors, "");
MyXSLProc xslProc = new MyXSLProc();

Element root = AddDOM.getDocumentElement();
Element reason = AddDOM.createElement("reason");
reason.appendChild(AddDOM.createTextNode(reason1));

root.appendChild(reason);

xslProc.process(request, response, "/medicare/ReferPatient.xsl", AddDOM);
return;

}

Doctor currentDoctor = Doctor.load(session, con);

Patient thispatient = Patient.load(patientId, con);
String patientName = thispatient.getFirstname()+" "+thispatient.getSurname();

Doctor sendToDoctor = Doctor.load(docId, con);

String[] doctorEmail = new String[1];
doctorEmail[0] = sendToDoctor.getEmail().toString();

String fromUser = currentDoctor.getEmail().toString();

String emailSubject = "Patient "+patientName+" Referral";

String emailContent = "F.A.O. Dr. "+sendToDoctor.getFirstname()+" "+sendToDoctor.getSurname()+",\n\nRE: Patient

Referral "+patientName+" ("+patientId+") \n\nNotes:\n"+notes+"\n\nSender Dr. "+currentDoctor.getFirstname()+"

"+currentDoctor.getSurname();

try {
this.sendEmail(doctorEmail, emailSubject, emailContent, fromUser);
} catch (Exception e) {
System.err.println("An error occured sending email: "+e);
}

String reason1 = "Referral email has been sent to: "+sendToDoctor.getEmail();
AbstractItem[] outItem = {};

Document AddDOM = createDom(outItem, "");
MyXSLProc xslProc = new MyXSLProc();

Element root = AddDOM.getDocumentElement();
Element reason = AddDOM.createElement("reason");
reason.appendChild(AddDOM.createTextNode(reason1));

root.appendChild(reason);

xslProc.process(request, response, "/medicare/ConfirmReferPatient.xsl", AddDOM);
return;
}


public void sendEmail(String doctorEmail[], String emailSubject, String emailContent, String fromUser){

try{
Properties smtps = new Properties();
smtps.put("mail.smtp.host", "smtp.btinternet.com");

javax.mail.Session emailSession = javax.mail.Session.getDefaultInstance(smtps, null);
emailSession.setDebug(false);

Message emailMessage = new MimeMessage(emailSession);

InternetAddress from = new InternetAddress(fromUser);
emailMessage.setFrom(from);

InternetAddress[] to = new InternetAddress[1];
to[0] = new InternetAddress(doctorEmail[0]);
emailMessage.setRecipients(Message.RecipientType.TO, to);

emailMessage.setSubject(emailSubject);
emailMessage.setContent(emailContent, "text/plain");

Transport.send(emailMessage);
} catch (Exception e) {
System.err.println("Major error in email :"+e);
}

}

}


 
Could it be a missing jar file? Tomcat would have to know where mailapi.jar, smtp.jar and activation.jar are...

Can you post the runtime exception you're getting?


"When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle
 
Indeed activation.jar and mail.jar were missing - added and it works perfectly (albeit for a Relaying denied error - but need to change the smtp server yet!)

Cheers!

Relisys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top