de.frame4j
Class SendMail

java.lang.Object
  extended by de.frame4j.util.App
      extended by de.frame4j.SendMail
All Implemented Interfaces:
AttrSettable, TextHelper.MessageComponents, UIInfo, ActionListener, EventListener, DynamicMBean

@MinDoc(copyright="Copyright 2002 - 2004 , 2009  A. Weinert",
        author="Albrecht Weinert",
        version="V.38",
        lastModified="10.04.2010",
        lastModifiedBy="A. Weinert",
        usage="start as Java application (-? for help)",
        purpose="a tiny E-mail sender (command line controlled)")
public class SendMail
extends App

A tiny E-Mail sender.

This application is a tiny command line controlled SMTP-Client using the JavaMail API (javax.mail).

On a successful execution this application send a plain text e-mail (BodyPart) and / or one or more file attachments (Multipart) to one or more addressees.

By start arguments, by an extra .properties file or by an RFC822 e-mail definition file among others the following mail properties may be specified:

The content of a text file (or URL) or the text property set by command line options may be taken as A RFC822 mail definition file may define the content and all header fields a in the following example:
  From    : the cheap provider <dev.executive@sioux.tv>
  To      : the customer <dear.customer@customers-ltd.tv>
  Reply-To: call centre <pontius.pilatus@sioux.tv>
  Subject : You are disconnected after your Western Union payment
  
  This mail was only send to you to keep you calm. You should get the
  impression your error report is taken seriously and the repair is under
  way. But this is just an automated response by a clever computer
  programme.
  
  Thank you for your endless patience.
  
On such RFC822 mail definitions the very first empty line is the separation of the header definitions from the (optional) mail text.

Hint 1: The basic .properties file named SendMail.properties is an integral part of this application and may be considered as part of the documentation.

Hint 2: This application also has a convenience starter SendMail in the anonymous package.

Hint 3: In a RFC-822 definition one can give lists of addressees for To, CC and BCC. The list separator has to be (best) 1 comma (,) + + 1 line + 1 space.

Hint 4: The separating line between header definitions and text body has to be absolutely empty (otherwise "miracles" occur). This missing robustness bug is RFC 822 taken to SUN's Java mail API. (to do in a later version: parse here robustly.)

Hint 5: On your server the default settings can (should) be overridden by placing a file SendMail.properties in jdk\jre\lib defining (at least) the following properties according to your environment:
 #  Property-File for SendMail.java  (jdk\jre\lib\SendMail.properties)
 #  V1.0  (So, 04.04.2010, 21:57 MEZ)
 #  for location / server: @ home 
 #  A. Weinert changes for 1&1
 #
 mail.from= no.reply@frame4j.de
 mail.smtp.host = smtp.1und1.de
 userName= ano.reply@frame4j.de
 # use the next line if you like it here more than in the command line
 # userPass=monRepos
 proxySet = false
 mail.smtp.auth = true
 # if behind a proxy say:
 # proxySet   = true
 # proxyHost  = myCompany'sProxy
 # proxyPort  = 8080

© Copyright 2002 - 2003, 2006   Albrecht Weinert

See Also:
InternetAddress, MimeMessage

Field Summary
 String attach
          First attachment file.
 String bcc
          The secret copy recipient(s) (may be a list).
 String cc
          The copy recipient(s) (may be a list).
 String contFile
          The content file.
 String contFileEncoding
          File encoding for content file.
 int contLogLength
          Log length of content.
 boolean parse
          The file is not only the content.
 String proxyHost
          The proxy server's name.
 String proxyPort
          The proxy server's port.
 boolean proxySet
          Use a proxy server connecting to mail host.
 String subject
          The subject.
 String text
          The content.
 String timeFormat
          Format for time stamp.
 boolean timeStamp
          Set actual time stamp.
 String to
          The recipient(s) (may be a list).
 String userName
           
 String userPass
           
 
Fields inherited from class de.frame4j.util.App
ano, appBase, appIO, appStartTime, args, bgColor, err, fullClassName, help, icon, INIT_ERROR, jmxRemoteNote, JOB_DONE_OK, log, LOG_OUT_ERROR, MAIN_THREAD_EXC, mainThread, myClass, myFrame, name, NO_PARS_ERROR, objectName, out, outMode, packName, prop, retCode, runFlag, shortClassName, title, verbose, verbosity
 
Fields inherited from interface de.frame4j.net.AttrSettable
ILLEGAL_TYPE, ILLEGAL_VALUE, NO_ATTRIBUTE, NO_KNOWN_ATTRIBUTE, NO_VALUE, OK
 
Constructor Summary
SendMail()
           
 
Method Summary
 int doIt()
          Working method of SendMail.
static void main(String[] args)
          Start method of SendMail.
 
Methods inherited from class de.frame4j.util.App
actionPerformed, allowNoPropertiesFile, clientOrder, condHelpLog, connect, errMeld, errMeld, errorExit, errorExit, errorExit, errorText, formMessage, formMessage, getAbout, getAboutText, getActTime, getAppLogger, getAppStartTime, getArgs, getAttribute, getAttributes, getAuthor, getCopyright, getDbLogger, getExecTimeMs, getExecTimeString, getHelp, getHelpText, getIcon, getLanguage, getLogHandler, getMBeanInfo, getMessageComponent, getMessageComponentsLength, getMyFrame, getName, getNameWithVersDate, getOutMode, getProp, getPurpose, getStartTime, getStateString, getTitle, getUsage, getVerbosity, getVerbosityString, getVersDate, getXMLinput, go, go, go, haveIcon, invoke, isDebug, isHelp, isHelpLog, isNormal, isRunFlag, isSilent, isTest, isVerbose, logVerbose, logVerbose, makeDbLogger, makeMenuBar, makeMenuBar, makeStatusTextEnd, makeStatusTextStart, messageFormat, normalExit, parsePartial, performeAction, postDeregister, postRegister, preRegister, queueAction, registerAsMBean, setAboutText, setAttribute, setAttribute, setAttribute, setAttributes, setAuthor, setBgColor, setCodePages, setCopyright, setHelp, setJmxRemoteNote, setLogOut2, setName, setOutMode, setOutMode, setPurpose, setTitle, setUsage, setVerbose, setVerbose, setVerbosity, setVerbosity, setVerbosityString, setVersDate, stop, threeLineEndMsg, toString, twoLineEndMsg, twoLineStartMsg, valueLang, valueLang, wakeMainThread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

contLogLength

public int contLogLength
Log length of content.

If App.verbose is true the mail content will be logged, but truncated in the log output after a maximum of contLogLength characters. The truncation does not happen if contLogLength is <= 42. If the mail text is truncated in the log, that will be signalled by dots ( ....).

Default: see SendMail.properties.


to

public String to
The recipient(s) (may be a list).

This denotes the mail's recipient. It may be a comma-separated list of more than one recipient. If used together with a RFC822 parsed file this properties specifies additional recipient(s). Additional means that in case of parseed RFC 822 definition file contFile that will be added to the addressees defined in the parsed file.

Default: see SendMail.properties.


cc

public String cc
The copy recipient(s) (may be a list).

This denotes the mail's copy recipient. The same conditions as for the to property apply.

Default: null


bcc

public String bcc
The secret copy recipient(s) (may be a list).

This denotes the mail's secret or blind copy recipient. The same conditions as for the to property apply.

Default: null


subject

public String subject
The subject.

For the mail's subject (header) field.

Default: seeSendMail.properties.


timeStamp

public boolean timeStamp
Set actual time stamp.

If true the mails's date (header) field will be set by the actual time.

Default: false.

See Also:
toRFCString(), toGMTString()

timeFormat

public String timeFormat
Format for time stamp.

If timeStamp is true, this format will be used for the mails's date (header) field.

Default: "r" (meaning ugly rfc822 standard)

See Also:
ConstTime.toString(CharSequence)

text

public String text
The content.

The (normal) text content of the mail (if any).
Will be set by start argument, .properties file or by a file (contFile) read.


contFile

public String contFile
The content file.

If contFile is not empty, it is tried to read the mail's text content directly from there respectively to parse the whole RFC822 mail definition from it.
contFile may denote a file or an URL.

Default: null


parse

public boolean parse
The file is not only the content.

If parse is true the file or URL denoted by contFile will not be taken for content only, but parsed as whole RFC 822 mail definition.

Default: false (set by options)


contFileEncoding

public String contFileEncoding
File encoding for content file.

If contFile is not empty, it is tried to read the mail's text content directly from there respectively to parse the whole RFC822 mail definition from it.
In that case contFileEncoding will be used for that file or URL.

Default: null, meaning the platform's encoding (mostly 8859-1 on European Windows)


attach

public String attach
First attachment file.

If attach is nor empty it is tried to add the file denoted by it as a true attachment to the mail.

In case of success a property attach2, attach3 and so on is looked for and treated in the same way.

Default: null


userName

public String userName

userPass

public String userPass

proxySet

public boolean proxySet
Use a proxy server connecting to mail host.

If true a proxy will be used to connect to the mail server and the properties proxyHost and proxyHost are in effect.

Default: false


proxyHost

public String proxyHost
The proxy server's name.

Default: "cache"

See Also:
proxySet

proxyPort

public String proxyPort
The proxy server's port.

Default: 8080

See Also:
proxySet
Constructor Detail

SendMail

public SendMail()
Method Detail

main

public static void main(String[] args)
Start method of SendMail.

Execution is : Java SendMail [options] [contFile] | [-help]

Parameters:
args - command line parameter
See Also:
doIt(), App.go(String[], boolean)

doIt

public int doIt()
Working method of SendMail.

Specified by:
doIt in class App
See Also:
main(Strin[]), App.go(String[], boolean)