增加 welcome-file 以支持 Tomcat 7 下根路径可以被 map 到 LoginServlet。
[jibu.git] / plugins / jibu-mail / src / main / java / org / gaixie / jibu / mail / JavaMailSender.java
blobaf072615687efadcc44692f8202f9cc0bd2b9e5e
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.gaixie.jibu.mail;
19 import java.util.Properties;
20 import javax.mail.Message;
21 import javax.mail.MessagingException;
22 import javax.mail.internet.MimeMessage;
23 import javax.mail.Session;
24 import javax.mail.Transport;
25 import javax.mail.internet.AddressException;
26 import javax.mail.internet.InternetAddress;
28 /**
29 * JavaMail class.
31 public class JavaMailSender {
33 /**
34 * 通过 javax.mail 发送邮件。
35 * <p>
37 * @param from 发送方邮件地址。
38 * @param recipients 接收方邮件地址,多个邮件地址以逗号分隔。
39 * @param subj 邮件标题。
40 * @param text 邮件正文。
42 public void sendEmail(String from, String recipients, String subj, String text) {
43 Properties props = new Properties();
44 Session session = Session.getDefaultInstance(props, null);
45 try {
46 InternetAddress[] address = InternetAddress.parse(recipients);
47 Message msg = new MimeMessage(session);
48 msg.setFrom(new InternetAddress(from));
49 msg.addRecipients(Message.RecipientType.TO,address);
50 msg.setSubject(subj);
51 msg.setText(text);
52 Transport.send(msg);
53 } catch (AddressException e) {
54 System.out.println(e.getMessage());
55 } catch (MessagingException e) {
56 System.out.println(e.getMessage());