Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: gsoft/util/Letter.java


1   /*************************************************************************
2   Copyright (C) 2003  Steve Gee
3   stevesgee@cox.net
4   
5   This program is free software; you can redistribute it and/or
6   modify it under the terms of the GNU General Public License
7   as published by the Free Software Foundation; either version 2
8   of the License, or (at your option) any later version.
9   
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *************************************************************************/
19  
20  package gsoft.util;
21  
22  import java.util.Vector;
23  import javax.activation.*;
24  import javax.mail.*;
25  import javax.mail.internet.*;
26  
27  
28  public class Letter implements java.io.Serializable{
29  
30    public String SENDER;
31    public String SUBJECT = "";
32    public String MAILSERVER;
33    public String[] MAIL_TO = null;
34    private Vector mailVec = new Vector();
35    private Multipart message = new MimeMultipart();
36  
37    public String getMailServer() { return MAILSERVER;  }
38    public void setMailServer(String s) { MAILSERVER =s;  }
39  
40    public InternetAddress getSender() throws Exception{ return new InternetAddress(SENDER);}
41    public void setSender(String a){SENDER = a; }
42  
43    public String getSubject(){ return SUBJECT;}
44    public void setSubject(String a){SUBJECT = a; }
45  
46    public void setRecipient(String s) {mailVec.addElement(s);}
47    public void setRecipients(String[] mailto) {MAIL_TO = mailto;}
48  
49    public InternetAddress[] getRecipients() throws Exception{
50      InternetAddress[] address = null;
51      if (mailVec.size() > 0) {
52        int size = mailVec.size();
53        int counter = 0;
54        address = new InternetAddress[size];
55        while (counter < size) {
56          address[counter] = new InternetAddress((String)mailVec.elementAt(counter));
57          counter++;
58        }
59      }else {
60        int size = MAIL_TO.length;
61        int counter = 0;
62        address = new InternetAddress[size];
63        while (counter < size) {
64          address[counter] = new InternetAddress(MAIL_TO[counter]);
65          counter++;
66        }
67      }
68       return address;
69     }
70  
71     public void addTextBody(String body) throws Exception{
72       MimeBodyPart mbp = new MimeBodyPart();
73       mbp.setText(body);
74       message.addBodyPart(mbp);
75     }
76  
77     public void addFileByString(String fileName) throws Exception{
78       MimeBodyPart mbp = new MimeBodyPart();
79       FileDataSource fds = new FileDataSource(fileName);
80      mbp.setDataHandler(new DataHandler(fds));
81       message.addBodyPart(mbp);
82     }
83  
84     public void addFile(MimeBodyPart mbp) throws Exception{
85       message.addBodyPart(mbp);
86     }
87  
88    public Multipart getMessage() {
89      return message;
90    }
91  
92  }