com.java4less.rmail
Class MailMsg

java.lang.Object
  |
  +--com.java4less.rmail.MailMsg

public class MailMsg
extends java.lang.Object

This class represents an e-mail message. In order to send a mail you must create one instance onf this class and call the "mail()" mehtod. Example:

Sending an email and attachment 

This is a sample source code to send an email:

m=new MailMsg();                                                // create email
m.from="user1@mycompany.com";                        // sender and receiver
m.addRecipient("user2@mycompany.com");
m.subject="test";
part=new MainMsgPart();                                    // add text part
part.setData("This is the text",MimeEncoder.QUOTED);
part.addPart(part);
m.addFile(new java.io.File("c:\\mydocument.doc"));  // add attachment
m.smtpServer="smtp.mycompany.com";
m.mail();                                                                // send mail

 

Sending alternative parts (Text and HTML)

This is a sample source code to send an email which contains two versions of the text (plain text and html):

m=new MailMsg();                                            // create email
m.from="user1@mycompany.com";                        // sender and receiver
m.addRecipient("user2@mycompany.com");
m.subject="test";


part=new MainMsgPart();                              // create alternative
part.ContentType="Multipart";
part.ContentSubType="Alternative";


textpart=new MainMsgPart();                                    // add text part to the alternative
textpart.setData("This is the text",MimeEncoder.QUOTED);
part.addPart(textpart);


htmlpart=new MainMsgPart();                                    // add html part to the alternative
htmlpart.ContentType="Multipart";
htmlpart.ContentSubType="Alternative";
htmlpart.setData("<html><body>This is the text</body></html>",MimeEncoder.QUOTED);
part.addPart(htmlpart);


m.addPart(part);
m.smtpServer="smtp.mycompany.com";
m.mail();                                                                      // send mail

 


Inner Class Summary
 class MailMsg.SMTP
           
 
Field Summary
 int AUTH_LOGIN
           
 int AUTH_NONE
           
 int AUTH_PLAIN
           
 java.lang.String authPwd
          smtp authentication password, see also autMethod
 java.lang.String authUser
          smtp authentication user, see also autMethod
 int autMethod
          authentication method, AUTH_LOGIN, AUTH_PLAIN or AUTH_NONE
 java.lang.String charSet
          Set of characters to be used.
 java.lang.String ContentSubType
          Content subtype of the e-mail.
 java.lang.String ContentType
          Content type of the e-mail.
 boolean debug
          debug
 java.lang.String FileName
           
 java.lang.String from
          e-mail address of the sender (e.g. user@company.com).
 ProgressSMTPListener liste
          listener of the message.
 java.lang.String msgId
          id of the message.
 java.lang.String nameFrom
          name of the sender of the mail
 java.lang.String[] otherFields
          Additional header fields in rfc822 format that should be sent.
 int partCounter
          number of parts in the message.
 java.lang.String rawHDR
          Header of the message as sent or received
 java.lang.String rawMsg
          Message as sent or received
 java.lang.String replyTo
          address to reply to.
 java.lang.String smtpDate
          date field of the smtp message.
 java.lang.String smtpMyAddress
          name/address of the computer sending the mail.
 int smtpPort
          smpt port to connect to.
 java.lang.String smtpServer
          smtpServer where to send the e-mail.
 java.lang.String smtpStatus
          description of the current status of the connection.
 java.lang.String subject
          subject of the e-mail.
 java.lang.String timeZoneStr
          time zone to be inserted in the date of the e-mail.
 
Constructor Summary
MailMsg()
           
 
Method Summary
 void addBCC(java.lang.String dest)
          adds a blind copy recipient.
 void addCC(java.lang.String dest)
          adds a carbon copy recipient.
 boolean addFile(java.io.File f)
          adds a new message part that will contain a file.
 void addPart(MailMsgPart p)
          add a new message part.
 void addRecipient(java.lang.String dest)
          adds a message recipient.
 MailMsgPart getPart(int num)
           
 int mail()
          sends the message.
static void MailMsg()
          creates a a new mail message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

from

public java.lang.String from
e-mail address of the sender (e.g. user@company.com).

nameFrom

public java.lang.String nameFrom
name of the sender of the mail

subject

public java.lang.String subject
subject of the e-mail.

smtpServer

public java.lang.String smtpServer
smtpServer where to send the e-mail.

timeZoneStr

public java.lang.String timeZoneStr
time zone to be inserted in the date of the e-mail. The default is GMT.

replyTo

public java.lang.String replyTo
address to reply to.

msgId

public java.lang.String msgId
id of the message. If empty the system will create one.

charSet

public java.lang.String charSet
Set of characters to be used. The default is "us-ascii". Other possible are: iso-8859-1, iso-8859-2 ...

ContentType

public java.lang.String ContentType
Content type of the e-mail. This value if optional. If the email has more one part its value will be "multipart". Other values are: "Text" (the mail contains text), "Message" (it contains another message), or "Application" (it contains binary data).

ContentSubType

public java.lang.String ContentSubType

Content subtype of the e-mail. This must have a value if the Content type has a value. Valid combinations of type / subtype are:

or any other valid Mime type.


otherFields

public java.lang.String[] otherFields
Additional header fields in rfc822 format that should be sent. For example:
"X-Sender: bwinters"

smtpStatus

public java.lang.String smtpStatus
description of the current status of the connection. It should only be used for user feedback.

smtpMyAddress

public java.lang.String smtpMyAddress
name/address of the computer sending the mail.

smtpPort

public int smtpPort
smpt port to connect to. The default is 25.

rawHDR

public java.lang.String rawHDR
Header of the message as sent or received

rawMsg

public java.lang.String rawMsg
Message as sent or received

liste

public ProgressSMTPListener liste

listener of the message. This listener receives the status of the connection when it changes, it sould only be used for feedback (visualization) purposes.

 

FileName

public java.lang.String FileName

smtpDate

public java.lang.String smtpDate
date field of the smtp message. For example: 5 May 2000 15:58:38 -0500. This field is automatically calculated if empty.

authUser

public java.lang.String authUser
smtp authentication user, see also autMethod

authPwd

public java.lang.String authPwd
smtp authentication password, see also autMethod

AUTH_LOGIN

public final int AUTH_LOGIN

AUTH_PLAIN

public final int AUTH_PLAIN

AUTH_NONE

public final int AUTH_NONE

autMethod

public int autMethod
authentication method, AUTH_LOGIN, AUTH_PLAIN or AUTH_NONE

partCounter

public int partCounter
number of parts in the message.

debug

public boolean debug
debug
Constructor Detail

MailMsg

public MailMsg()
Method Detail

MailMsg

public static void MailMsg()
creates a a new mail message.

getPart

public MailMsgPart getPart(int num)

addFile

public boolean addFile(java.io.File f)
adds a new message part that will contain a file.

addPart

public void addPart(MailMsgPart p)
add a new message part.

addRecipient

public void addRecipient(java.lang.String dest)
adds a message recipient.

addCC

public void addCC(java.lang.String dest)
adds a carbon copy recipient.

addBCC

public void addBCC(java.lang.String dest)
adds a blind copy recipient.

mail

public int mail()
sends the message.