com.javaranch.common
Class Email

java.lang.Object
  |
  +--com.javaranch.common.Email

public class Email
extends java.lang.Object

Emails a message to a user.

This class provides a central place for eliminating redundant email code.
Define your SMTP server once, and all future emails use that server.

- - - - - - - - - - - - - - - - -

Copyright (c) 1999-2004 Paul Wheaton

Copyright (c) 1999-2000 EarthWatch, Inc. You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...

My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.

I originally developed this class while working as a contractor at EarthWatch, Inc. in Longmont, Colorado. They gave me permission to distribute this code this way provided that their message would also be carried along. Their message is that they hire Java programmers and would like you to consider working with them. I have to say that my experience with them was first rate and I would encourage engineers to work there. Check out their web site at http://www.digitalglobe.com.

The original source can be found at JavaRanch

- - - - - - - - - - - - - - - - -

Author:
Paul Wheaton

Field Summary
static java.lang.String smtpServerKey
           
 
Constructor Summary
Email()
           
 
Method Summary
static java.lang.String getAdminEmail()
           
static void reportError(java.lang.String message)
          Send an e-mail to the admin, from the admin defined by the setAdminEmail() method via the specified server defined via the setSMTPServer() method.
static void send(java.lang.String from, java.lang.String body)
          Send an e-mail to the admin defined by the setAdminEmail() method and the server defined via the setSMTPServer() method.
static void send(java.lang.String to, java.lang.String from, java.lang.String subject, java.lang.String body)
          SMTP server must be defined via the setSMTPServer() method before you can use this method.
static void setAdminEmail(java.lang.String adminEmail)
           
static void setSMTPServer(java.lang.String smtpServer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

smtpServerKey

public static final java.lang.String smtpServerKey
See Also:
Constant Field Values
Constructor Detail

Email

public Email()
Method Detail

setSMTPServer

public static void setSMTPServer(java.lang.String smtpServer)
Parameters:
smtpServer - for example, "192.168.1.1", "mail.megacorp.com", "127.0.0.1", etc.

getAdminEmail

public static java.lang.String getAdminEmail()

setAdminEmail

public static void setAdminEmail(java.lang.String adminEmail)

send

public static void send(java.lang.String to,
                        java.lang.String from,
                        java.lang.String subject,
                        java.lang.String body)
                 throws java.lang.Exception
SMTP server must be defined via the setSMTPServer() method before you can use this method.

java.lang.Exception

send

public static void send(java.lang.String from,
                        java.lang.String body)
                 throws java.lang.Exception
Send an e-mail to the admin defined by the setAdminEmail() method and the server defined via the setSMTPServer() method.

java.lang.Exception

reportError

public static void reportError(java.lang.String message)
Send an e-mail to the admin, from the admin defined by the setAdminEmail() method via the specified server defined via the setSMTPServer() method.

If there are any problems, write the problem to the System.err.



Copyright ©2004 Paul Wheaton All Rights Reserved