wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Mail send in struts" Watch "Mail send in struts" New topic
Author

Mail send in struts

maha lakshmi
Greenhorn

Joined: Feb 22, 2008
Posts: 7
Hi
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
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[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.


Merrill
Consultant, Sima Solutions
maha lakshmi
Greenhorn

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

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.security.Security;
import java.util.Properties;

public class MyGoogleMailSender {

private int x;

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

String SMTP_HOST_NAME = "smtp.gmail.com";
String SMTP_PORT = "465";
String emailMsgTxt = "mail body";
String emailSubjectTxt = "subject";
String emailFromAddress = "...@gmail.com";
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
String[] sendTo = {"...@gggg.com"};
//String toBeSent="whatever@yahoo.com.com";

String recipients[]=new String[1];
recipients[0]="...@mail.com";
//System.out.print(recipients[0]);

Properties props = new Properties();
props.put("mail.smtp.host", 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("...@gmail.com", "password");
}
});

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

InternetAddress[]
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.setSubject(emailSubjectTxt);
msg.setContent(emailMsgTxt, "text/plain");
//Transport.send(msg);



Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
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: http://aspose.com/file-tools
 
subject: Mail send in struts
 
Similar Threads
convertNull in struts1.3
Struts1.3 tiles problem
struts1.3 with hibernate
session in struts1.3
Session Timeout in Struts1.3