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
  • 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?");
LVL 16

Author Comment

ID: 12056678
Thank you.

Do I need someother tool such as email server or etc ?
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 38
network + 7 80
eclipse package explorer vs project explorer view 2 74
eclipse java  build path 6 43
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now