Solved

How to send an email from a Java-program

Posted on 2004-03-25
3
183 Views
Last Modified: 2013-11-24
The code looks like:

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

0
Comment
Question by:chenwei
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Updating Java 9 87
Exception after setting jdbc session management 2 38
Modeling a class in java 5 31
Java asynchronous logging 4 34
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…
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…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

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

21 Experts available now in Live!

Get 1:1 Help Now