[--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]