Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

sending email jsp

Posted on 2003-03-12
2
Medium Priority
?
165 Views
Last Modified: 2010-04-01
Can some one please give me a sample mail jsp/bean !!!!!!
0
Comment
Question by:rax_uk2000
2 Comments
 

Accepted Solution

by:
rakeshkumar_12 earned 300 total points
ID: 8120272
This code sends mail using java mail

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.FileDataSource;
import javax.activation.DataHandler;


// This method send a message
     public boolean sendJavaMail(String host, String from, String to,
String cc, String bcc, String subject, String message, String mimeType)
  {
    Properties props = new Properties();
    props.put("mail.smtp.host", host);

    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(false);

    try
    {
      //Message msg = new MimeMessage(session);
      MimeMessage msg = new MimeMessage(session);

      InternetAddress from2 = new InternetAddress(from);
      msg.setFrom(from2);

      InternetAddress[] to2 =  InternetAddress.parse(to);
      msg.setRecipients(Message.RecipientType.TO, to2);

      if(cc != null)
      {
        if(!(cc.trim().equals("")))
        {
          InternetAddress[] cc2 =  InternetAddress.parse(cc);
          msg.setRecipients(Message.RecipientType.CC, cc2);
        }
      }

      if(bcc !=null)
      {
        if(!(bcc.trim().equals("")))
        {
          InternetAddress[] bcc2 =  InternetAddress.parse(bcc);
          msg.setRecipients(Message.RecipientType.BCC, bcc2);
        }
      }

      // Create subject
      msg.setSubject(subject);

      // Create and fill the first message part
      MimeBodyPart mbp1 = new MimeBodyPart();
      mbp1.setContent(message, mimeType);

      // Create the Multipart and its parts to it
      Multipart mp = new MimeMultipart();
      mp.addBodyPart(mbp1);

      // Add the Multipart to the message
      msg.setContent(mp);

      Transport.send(msg);    
               
               return true;
    }
    catch (MessagingException ex)
    {
      ex.printStackTrace();
               
               return false;
    }
  }


Good luck

0
 

Author Comment

by:rax_uk2000
ID: 8120291
thanks that will do nicely !
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Choosing the right mix of apps is very much necessary for CPAs for making the most of the latest technology through which they can boost their growth.
The number of companies understanding the potential of IoT on B2B market is growing with each day. And yet only a small share of IoT developers have managed to equalize incomes and stay competitive in the international market.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

577 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