You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "C.F. Scheidecker Antunes" <na...@antunes.eti.br> on 2005/10/24 07:19:04 UTC
need to email from action
Hello all,
I need to email a simple text message from within an action.
I've tried creating a class using javax.mail.* and javax.mail.internet.*
classes but without success.
I wonder if there is any simple recipe for that.
Thanks,
C.F.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: need to email from action
Posted by Xavier Vanderstukken <xv...@ionicsoft.com>.
Jakarta commons-email is your friend
http://jakarta.apache.org/commons/email/examples.html
C.F. Scheidecker Antunes wrote:
> Hello all,
>
> I need to email a simple text message from within an action.
>
> I've tried creating a class using javax.mail.* and
> javax.mail.internet.* classes but without success.
>
> I wonder if there is any simple recipe for that.
>
> Thanks,
>
> C.F.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: need to email from action
Posted by Murray Collingwood <mu...@focus-computing.com.au>.
I made this generic static class which I can call from anywhere in my app. Of course
you need the JavaMail library.
import java.util.Date;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class Send {
private static final String smtpServer = "localhost";
private static final String smtpPort = "25";
private static final String smtpSender = "fromAddress@mydom.com";
public Send() {
}
public static String message(String to, String sub, String body) {
try {
Properties props = System.getProperties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.port", smtpPort);
props.put("mail.from", smtpSender);
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
msg.setFrom(InternetAddress.getLocalAddress(session));
msg.setSubject(sub);
msg.setText(body);
msg.setSentDate(new Date());
Transport.send(msg);
} catch (Exception e) {
System.err.println("ERROR: FOCUS: Send: sendmail error: " +
e.getMessage());
return e.getMessage();
}
return "";
}
}
HTH
Murray
On 23 Oct 2005 at 23:19, C.F. Scheidecker Antunes wrote:
> Hello all,
>
> I need to email a simple text message from within an action.
>
> I've tried creating a class using javax.mail.* and javax.mail.internet.*
> classes but without success.
>
> I wonder if there is any simple recipe for that.
>
> Thanks,
>
> C.F.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.361 / Virus Database: 267.12.4/146 - Release Date: 21/10/2005
>
FOCUS Computing
Mob: 0415 24 26 24
murray@focus-computing.com.au
http://www.focus-computing.com.au
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.361 / Virus Database: 267.12.4/146 - Release Date: 21/10/2005
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org