File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Mail send in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Mail send in struts" Watch "Mail send in struts" New topic

Mail send in struts

maha lakshmi

Joined: Feb 22, 2008
Posts: 7
i am using struts1.3 frame work. my mail sending java code working servlet but i dont know how to integrate in struts1.3 please help me.

Thanks in advance...
Joe Ess

Joined: Oct 29, 2001
Posts: 9168

Exactly what is your problem? Do you understand how Struts works?

[How To Ask Questions On JavaRanch]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Use of the Java Mail API isn't going to be any different in a Struts Action that it would be in a Servlet. You should be able to pretty much cut and paste the code from your Servlet into an Action class. Better yet, create a POJO that handles interaction with Java Mail having methods that can be called either from a Servlet or an Action class.

Consultant, Sima Solutions
maha lakshmi

Joined: Feb 22, 2008
Posts: 7
Thank you...
its working fine....
kaan h.

Joined: Apr 06, 2008
Posts: 5
that code can help you. You shoul send mail in a seperate thread..:

//designed (will be transformed for the framework) for struts framework uses gmail. Username and password are included in the code.

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class MyGoogleMailSender {

private int x;

public static void main(String args[]) throws Exception {

String SMTP_HOST_NAME = "";
String SMTP_PORT = "465";
String emailMsgTxt = "mail body";
String emailSubjectTxt = "subject";
String emailFromAddress = "";
String SSL_FACTORY = "";
String[] sendTo = {""};
//String toBeSent="";

String recipients[]=new String[1];

Properties props = new Properties();
props.put("", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");

Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
// buraya gmail mail adresinizi ve sifrenizi girmelisiniz.
return new PasswordAuthentication("", "password");

Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(emailFromAddress);

addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
msg.setRecipients(Message.RecipientType.TO, addressTo);

msg.setContent(emailMsgTxt, "text/plain");

new GoogleMailSender().sendSSLMessage(
sendTo, emailSubjectTxt, emailMsgTxt, emailFromAddress);
System.out.println("Sucessfully Sent mail to All Users");
}//end main

}//end class
[ July 03, 2008: Message edited by: kaan h. ]
I agree. Here's the link:
subject: Mail send in struts
jQuery in Action, 3rd edition