Solved

How to send an email from a Java-program

Posted on 2004-03-25
3
188 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 50 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 …

730 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