thanks i guess ill just modify and reuse this.
On Wed, 13 Oct 2004 09:43:39 +0100, Duncan Mills <[EMAIL PROTECTED]> wrote: > Its pretty simple to plug in the JavaMail API - here's a Utility class I > call from an Action I use when resetting a User Password: It's quick and > dirty but provides an example. The SMTP mail host is read from a > properties file in this case, but equally could be passed in from the > Appliciation scope. Note the total lack of any kind of useful error > handling in this example - I think I better re-write it :-) > > [--Badly formmated code begin--] > package com.groundside.util; > import java.io.IOException; > import java.io.InputStream; > import java.util.Properties; > import javax.mail.Message; > import javax.mail.MessagingException; > import javax.mail.Session; > import javax.mail.Transport; > import javax.mail.internet.InternetAddress; > import javax.mail.internet.MimeMessage; > > public class Emailer > { > String toAddress; > String fromAddress; > String msgText; > String smtpServer; > String msgSubject; > > public Emailer() > { > } > > public Emailer(String from, String to, String subject, String message) > { > setFromAddress(from); > setToAddress(to); > setMsgSubject(subject); > setMsgText(message); > } > > public void sendMail() > { > Session session = null; > MimeMessage msg = null; > Properties props = new Properties(); > > if (this.getSmtpServer() == null) > { > ClassLoader propLoader = this.getClass().getClassLoader(); > //Properties file just lives in the src root > InputStream is = propLoader.getResourceAsStream("mailer.properties"); > try > { > props.load(is); > setSmtpServer((String)props.get("mail.smtp.host")); > } > catch (IOException iox) > { > System.out.println("Mail Properties load failed " + iox.toString()); > } > > } > else > { > props.put("mail.smtp.host",this.getSmtpServer()); > } > > session = Session.getDefaultInstance(props); > try > { > msg = new MimeMessage(session); > > msg.setFrom(new InternetAddress(this.getFromAddress())); > msg.addRecipient(Message.RecipientType.TO,new > InternetAddress(this.getToAddress())); > msg.setSubject(getMsgSubject()); > msg.setText(getMsgText()); > > Transport.send(msg); > } > catch (MessagingException mex) > { > mex.printStackTrace(); > } > > } > > // Getters and Setters > public String getToAddress() > { > return toAddress; > } > > public void setToAddress(String toAddress) > { > this.toAddress = toAddress; > } > > public String getFromAddress() > { > return fromAddress; > } > > public void setFromAddress(String fromAddress) > { > this.fromAddress = fromAddress; > } > > public String getMsgText() > { > return msgText; > } > > public void setMsgText(String msgText) > { > this.msgText = msgText; > } > > public String getSmtpServer() > { > return smtpServer; > } > > public void setSmtpServer(String smtpServer) > { > this.smtpServer = smtpServer; > } > > public String getMsgSubject() > { > return msgSubject; > } > > public void setMsgSubject(String msgSubject) > { > this.msgSubject = msgSubject; > } > } > > [--Badly formmated code end--] > > Regards > > Duncan Mills > > > Richard wrote: > > >hi guys > > > > > >I have a form submitted to an action class and i need the information > >on the form to be emailed > >to some email address. how can i do this ? can it be done inside the > >same action? > > > >please help > >thanks > >richard > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]