KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > util > GeiMailSender


1 /*
2 -- GeiNuke --
3 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
4 http://www.hostingjava.it/-geinuke/
5
6 This file is part of GeiNuke.
7
8    GeiNuke is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    GeiNuke is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GeiNuke; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */

22 package com.geinuke.util;
23
24 import java.util.ArrayList JavaDoc;
25
26 import org.apache.commons.mail.HtmlEmail;
27 import org.springframework.mail.SimpleMailMessage;
28 import org.springframework.mail.javamail.JavaMailSenderImpl;
29
30
31 public class GeiMailSender {
32     
33     protected JavaMailSenderImpl ms=null;
34     String JavaDoc smtp=null;
35     public GeiMailSender(String JavaDoc smtp){
36         this.smtp=smtp;
37         this.ms=new JavaMailSenderImpl();
38         this.ms.setHost(smtp);
39     }
40     public void sendMail(String JavaDoc from,String JavaDoc[] to,String JavaDoc text,String JavaDoc subject){
41         
42         HtmlEmail hm=new HtmlEmail();
43         hm.setHostName(this.smtp);
44         ArrayList JavaDoc list=new ArrayList JavaDoc();
45         for(int i=0;i<to.length;i++)
46             list.add(to[i]);
47         try{
48             hm.setFrom(from);
49             hm.setHtmlMsg(text);
50             hm.setTo(list);
51             hm.setSubject(subject);
52             /*
53             SimpleMailMessage smm=null;
54             smm=new SimpleMailMessage();
55             smm.setFrom(from);
56             smm.setText(text);
57             smm.setTo(to);
58             smm.setSubject(subject);
59             this.ms.send(smm);
60             */

61             hm.send();
62         }catch(Exception JavaDoc e){
63             e.printStackTrace();
64         }
65     
66     }
67     
68 }
69
Popular Tags