?
Solved

How to send an email from a Java-program

Posted on 2004-03-25
3
Medium Priority
?
190 Views
Last Modified: 2013-11-24
The code looks like:

...
...
if(error_message)
  send_email(error_message, email_address);
...
...

0
Comment
Question by:chenwei
[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
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 10681150
You need to download and install http://java.sun.com/products/javamail/. It comes with examples

Or you might try this:


      public static void send_email(error_message, email_address) {
            try {
                  sun.net.smtp.SmtpClient client = new sun.net.smtp.SmtpClient("smtp.freeserve.net");
                  client.from("sysadmin@somewhere.com");
                  client.to("sysadmin@summer-retreat-about-to-be-irritated.com");
                  // or really 'email_address'
                  PrintWriter out = new PrintWriter(client.startMessage(), true);
                  out.println("Subject: Error");
                  out.println("Pack your bags chum and get back to the office pronto - here's the bad news:");
                  out.println(error_message);
                  client.closeServer();
                  System.out.println("Message sent");
            }
            catch (Exception e) {
                  e.printStackTrace();
            }

      }
0
 

Expert Comment

by:pradeepbkumar
ID: 10684617
U can as well use the "mailto" option of the JavaMail utility...

Rgds,
Ped
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10714089
8-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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