Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Emailing form based on selected options

Posted on 2006-06-12
11
Medium Priority
?
196 Views
Last Modified: 2011-04-14
What is the best way to email a form based on a selected radio button in Frontpage?
0
Comment
Question by:ITHelper80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
11 Comments
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16922225
....u mean send email from the data that is collected from the form using radio button.

Can u please explain more clearly

____Jags
0
 
LVL 6

Author Comment

by:ITHelper80
ID: 16922662
Sure....I guess I should have done that in the first place.

Ok here is the deal. I want to create an email form with lets say 5 radio buttons. If a user selects the first radio button then an email will be sent to a group with all the details of that radio button, if the second radio button is selected then it goes to a different group, etc, etc. Does that help?
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16922733
ok....you might want to use some server-side tech...what are u using java or .net. A have a sample code that does something similar to that done using servlets and jsp .

_____Jags.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Author Comment

by:ITHelper80
ID: 16922785
Well thats the deal, Im not a web developer, this has just been dumped into my lap. Thats why I want something simple, I know right now we have tomcat running and use jsp, but I dont know how to use or code ethier.....
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16922821
ok...when u say u are not a web developer its a lot of work for you now. It really takes time for me to customize the code inorder to satisfy your needs. Instead i can give fragments of code that does your work . its a jsp page with 2 other servlets and a class file.

____Jags.
0
 
LVL 3

Expert Comment

by:gugfuz
ID: 16942345
Should this proces of emailing be invisible for the user, or don't you mind that the form opens an email with your data that the user has to send?
0
 
LVL 6

Author Comment

by:ITHelper80
ID: 16942961
I need it to be invisible to the user.
0
 
LVL 10

Expert Comment

by:jagadeesh_motamarri
ID: 16943052
ok...Sample Code for sending the email with out attachments -

CODE:

package njit.capstone.proj;

import java.io.File;
import java.security.Security;
import java.util.Date;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class mailingPackage {

      private static final String SMTP_HOST_NAME = "smtp.gmail.com";

      private static final String SMTP_PORT = "465";

      private static final String emailSubjectTxt = "A test from gmail";

      private static final String emailFromAddress = ""; // use from address here

      private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

      //private static final String[] sendTo = { "jagadeesh_motamarri@yahoo.com" };  
      private static String[] sendTo = null;

      public boolean sendMail1() {

            return true;
      }

      public static void main(String args[]) throws Exception {
            StringBuffer msg = new StringBuffer();
            String emailMsgTxt = msg.append(" " 
                                    "<html><body>Your html message or other message goes here </body></html>").toString();
            Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
            new mailingPackage().sendSSLMessage(sendTo, emailSubjectTxt,emailMsgTxt, emailFromAddress);
            System.out.println("Sucessfully Sent mail to All Users");
      }

      public void sendSSLMessage(String recipients[], String subject,      String message, String from) throws MessagingException {
            boolean debug = true;

            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() {
                                    return new PasswordAuthentication("username for gmail", "password for gmail"); // enter your gmail username and password - or any other as per the smpt
                              }
                        });

            session.setDebug(debug);

            Message msg = new MimeMessage(session);
            InternetAddress addressFrom = new InternetAddress(from);
            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);

            // Setting the Subject and Content Type
            msg.setSubject(subject);
            msg.setContent(message, "text/html");

            Transport.send(msg);
            System.out.println("Mail sent out Successfully");
      }

      // send mail to each person along with multiple attachments

      public void sendMailAttachments(String recipients, String subject, String message, String from, String filenames[]) throws MessagingException {
            
            System.out.println("Now in sendMailAttachments");
            
            boolean debug = true;

            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() {
                                    return new PasswordAuthentication("username for gmail", "password for gmail"); // enter your gmail username and password - or any other as per the smpt
                              }
                        });

            session.setDebug(debug);
            
             // Get a Transport object to send e-mail
        Transport bus = session.getTransport("smtp");

        // Connect only once here
        // Transport.send() disconnects after each send
        // Usually, no username and password is required for SMTP
        bus.connect();
        //bus.connect("smtpserver.yourisp.net", "username", "password");

       
        // Instantiate a message
        Message msg = new MimeMessage(session);
            
        //From Address
        InternetAddress addressFrom = new InternetAddress(from);
            msg.setFrom(addressFrom);
          
        // To Address
            String[] sendTo = { recipients };
            InternetAddress[] addressTo = new InternetAddress[sendTo.length];
            for (int i = 0; i < sendTo.length; i++) {
                  addressTo[i] = new InternetAddress(sendTo[i]);
            }
            msg.setRecipients(Message.RecipientType.TO, addressTo);
            
            // Sent Date
            msg.setSentDate(new Date());
            
            //set the subject of the mail
            msg.setSubject(subject);
          
            
            MimeBodyPart p1 = new MimeBodyPart();
            p1.setContent(message,"text/html");
            
            
            
          MimeBodyPart messageBodyPart=null;
          Multipart mp = new MimeMultipart();
      
          // attach the files in parts
          if(filenames!=null)
          for( int j = 0; j < filenames.length; j++ )
             {
                
                      
                    try{
                    messageBodyPart = new MimeBodyPart();
                    FileDataSource fileDataSource =new FileDataSource(filenames[j]);
                    messageBodyPart.setDataHandler(new DataHandler(fileDataSource));
                    messageBodyPart.setFileName(filenames[j].substring(filenames[j].lastIndexOf(File.separator)+1));
                    mp.addBodyPart(messageBodyPart);
                    }catch(Exception e){
                          e.printStackTrace();
                    }
                }
        
          // attach the body of the mail
          mp.addBodyPart(p1);
          msg.saveChanges();
          
          msg.setContent(mp);
          
          Transport.send(msg);
      
      }
      
}

----------------
Many things are customizable here... Now you need a  form and a servlet for sending multiple emails to many people at the same time.

Main method is the above class is - public void sendMailAttachments(String recipients, String subject, String message, String from, String filenames[])

All you got to do is when u click on a radio button...collect the names of the users user that button and grad them into a string of recipients seperted by commas. and call this method with its required attributes. That will solve your problem.

You can use a servlet for collecting the recipient addresses from the form.

_____Jags.
0
 
LVL 10

Accepted Solution

by:
jagadeesh_motamarri earned 2000 total points
ID: 16943072
small correction -

Actually the above class contains two methods

1. send mail without attachmets - public void sendSSLMessage(String recipients[], String subject,     String message, String from)
2. Send mail with attachments - public void sendMailAttachments(String recipients, String subject, String message, String from, String filenames[])

____Jags
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question