• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Mail send in struts

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly what is your problem? Do you understand how Struts works?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
maha lakshmi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you...
its working fine....
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 = "[email protected]";
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
String[] sendTo = {"[email protected]"};
//String toBeSent="[email protected]";

String recipients[]=new String[1];
recipients[0]="[email protected]";
//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("[email protected]", "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. ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic