Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to send an email from a Java-program

Posted on 2004-03-25
3
Medium Priority
?
191 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

618 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