Solved

Send Email

Posted on 2004-09-14
8
220 Views
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?

Thanks.
0
Comment
Question by:suprapto45
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 100 total points
ID: 12055118
0
 
LVL 6

Assisted Solution

by:expertmb
expertmb earned 50 total points
ID: 12055133
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 300 total points
ID: 12055157
import java.io.*;
    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("mail.smtp.host", 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));
            msg.setSubject(subject);
            msg.setText(content);
   
            // Send the message
            Transport.send(msg);
        }
   
        public static void main(String[] args) throws Exception {
            // Send a test message
            send("hostname", 25, "joe@smith.com", "sue@smith.com",
                 "re: dinner", "How about at 7?");
        }
    }
0
 
LVL 16

Author Comment

by:suprapto45
ID: 12056678
Thank you.

Do I need someother tool such as email server or etc ?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 16

Author Comment

by:suprapto45
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.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
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("192.12.0.1", 25, "joe@smith.com", "sue@smith.com",
                 "re: dinner", "How about at 7?");
        }

where 192.12.0.1 is where ur mail server is installed
0
 
LVL 1

Assisted Solution

by:achilka
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

or

Contact your system administrator for an email server hostname

or

user http://www.kloth.net/services/nslookup.php 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("mail.smtp.host", "smtp.mail.example.com");
  Session s = Session.getInstance(props,null);

  MimeMessage message = new MimeMessage(s);

  InternetAddress from = new InternetAddress("you@example.com");
  message.setFrom(from);
  InternetAddress to = new InternetAddress("you@example.com");
  message.addRecipient(Message.RecipientType.TO, to);
  to = new InternetAddress("me@example.com");
  message.addRecipient(Message.RecipientType.TO, to);
  to = new InternetAddress("jayson@jspinsider.com");
  message.addRecipient(Message.RecipientType.CC, to);

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

  Transport.send(message);
%>

0
 
LVL 37

Expert Comment

by:zzynx
ID: 12130587
Thanks for accepting
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 76
stringclean challenge 26 56
wordappend challenge 8 85
create a gui in perl 3 42
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

708 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

11 Experts available now in Live!

Get 1:1 Help Now