• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

How to send an email from a Java-program

The code looks like:

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

0
chenwei
Asked:
chenwei
  • 2
1 Solution
 
CEHJCommented:
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
 
pradeepbkumarCommented:
U can as well use the "mailto" option of the JavaMail utility...

Rgds,
Ped
0
 
CEHJCommented:
8-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now