/* Feb. 16, 2000 */ /* ***************************************************************************** Copyright 2000 by Erica Andrews (cylikon@hotmail.com). All rights reserved. ./ButchWhipAppeal/ ./IcedPinky/ NO portion of this software may be used in ANY way by anyone other than myself without my express written consent. If it is downloaded for testing, it must be deleted from your system within 24 hours. Any other use constitutes piracy and fraudulent misuse of this software, punishable in a court of law. Copyright 2000 by Erica Andrews. All rights reserved. ***************************************************************************** */ package mail; import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class MailSenderBean { public String TO = "whip1472@www.whip.com"; // a domain name only existant on my computer public String HOST = "127.0.0.1"; // loopback localhost private String FROM = null; private String SUBJECT = null; private String MESSAGE = null; private String userinfo = null; public void setFrom(String FROM2) { FROM = FROM2; this.FROM = FROM; } public String getFrom() { return FROM; } public void setSubject(String Subject2) { SUBJECT = Subject2; this.SUBJECT = SUBJECT; } public String getSubject() { return SUBJECT; } public void setMessage(String MESSAGE2) { MESSAGE = MESSAGE2; this.MESSAGE = MESSAGE; } public String getMessage() { return MESSAGE; } public void setUserinfo(String User) { userinfo = User; this.userinfo = userinfo; } public String getUserinfo() { return userinfo; } public Message SendMessage() throws AddressException, MessagingException { Session s = Session.getDefaultInstance(System.getProperties(),null); MimeMessage m = new MimeMessage(s); InternetAddress t = new InternetAddress(TO); InternetAddress f = new InternetAddress(getFrom()); m.addRecipients(Message.RecipientType.TO, new InternetAddress[]{t }); // TO addresss m.setFrom(f); // the FROM address m.setSubject("CJs IIS Site Comments: "+getSubject()); // message subject m.setContent(getMessage()+"\n\n Sender Info:"+getUserinfo(), "text/plain"); // message body m.setHeader("X-Mailer", "JavaMail API on JSP"); m.addHeaderLine("Email message sent using the JavaMail API on CJs IIS website"); // -- setting mail Priority for "high" in case the user is reporting site problems m.setHeader("x-priority", "1"); m.setHeader("x-msmail-priority", "high"); return m; } // end of SendMessage method // the method that actually transports the mail public String SendTheMail() { // doing some very simple message validation // do we have a valid address to send TO? // do we have a valid address to send FROM? // do we a message in the body of the email? if (TO == null || getFrom() == null || getMessage() == null) { if (TO == null) { return "No TO address specified, we can't send mail.";} // will not happen if (getFrom() == null) { return "No FROM address provided. Try again, please.";} if (getMessage() == null) { return "No MESSAGE specified. No empty emails, please"; } } else { // if we have the basics, let's try to send the mail try { Message msg = SendMessage(); Transport.send(msg); } catch (AddressException ae) { return "Problem sending mail... " +ae+" "+ae.getMessage();} catch (MessagingException me) { return "Problem sending mail... " +me+" "+me.getMessage();} //end of Try-Catch } // end of long If-Else statement return "\n End of Mail Session: Message successfully sent to the site owner. "; } // end of method } // end of class MailSenderBean