Send Email

Posted on 2004-09-14
Last Modified: 2013-11-24
Hi guys,

This question is related to my previous question. I am creating Intranet using JSP and Struts framework. Now, I want to be able to send email to some of the email addresses, how can I do that?

Question by:suprapto45
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
  • 2
  • 2
  • 2
  • +2
LVL 37

Assisted Solution

zzynx earned 100 total points
ID: 12055118

Assisted Solution

expertmb earned 50 total points
ID: 12055133
LVL 14

Accepted Solution

sudhakar_koundinya earned 300 total points
ID: 12055157
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class SendApp {
        public static void send(String smtpHost, int smtpPort,
                                String from, String to,
                                String subject, String content)
                throws AddressException, MessagingException {
            // Create a mail session
            java.util.Properties props = new java.util.Properties();
            props.put("", smtpHost);
            props.put("mail.smtp.port", ""+smtpPort);
            Session session = Session.getDefaultInstance(props, null);
            // Construct the message
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
            msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
            // Send the message
        public static void main(String[] args) throws Exception {
            // Send a test message
            send("hostname", 25, "", "",
                 "re: dinner", "How about at 7?");
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 16

Author Comment

ID: 12056678
Thank you.

Do I need someother tool such as email server or etc ?
LVL 16

Author Comment

ID: 12056694
Can anyone tell me how to configure it out in my network? I have one webserver, one database server and many client PC.
LVL 14

Expert Comment

ID: 12056738
and you must have one mail server to send the mail to external mail server

if u are using Winmdows IIS smtp will help you

If u are on Linux Box, It contains default mail server

As suggested in above example
 public static void main(String[] args) throws Exception {
            // Send a test message
            send("", 25, "", "",
                 "re: dinner", "How about at 7?");

where is where ur mail server is installed

Assisted Solution

achilka earned 50 total points
ID: 12059672
Here is how one can send emails to multiple recipients using jsp...before that you need to know the smtp mail server on your domain which can be queried using nslookup command like
nslookup ENTER
set query=MX ENTER
your_domain_name ENTER


Contact your system administrator for an email server hostname


user to lookup email server by typing your domain name and query to MX

JSP code...

<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
  Properties props = new Properties();
  props.put("", "");
  Session s = Session.getInstance(props,null);

  MimeMessage message = new MimeMessage(s);

  InternetAddress from = new InternetAddress("");
  InternetAddress to = new InternetAddress("");
  message.addRecipient(Message.RecipientType.TO, to);
  to = new InternetAddress("");
  message.addRecipient(Message.RecipientType.TO, to);
  to = new InternetAddress("");
  message.addRecipient(Message.RecipientType.CC, to);

  message.setSubject("Test from JavaMail.");
  message.setText("Hello from JavaMail!");


LVL 37

Expert Comment

ID: 12130587
Thanks for accepting

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Can anyone please tell me why i can not find ID  investorCoolGrid inside the jsp page? 1 23
mysql jsp example issue 32 70
java imports not found 4 47
JDBC performance 8 28
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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