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
;
31 public class JavaMailSender
{
37 * @param from 发送方邮件地址。
38 * @param recipients 接收方邮件地址,多个邮件地址以逗号分隔。
42 public void sendEmail(String from
, String recipients
, String subj
, String text
) {
43 Properties props
= new Properties();
44 Session session
= Session
.getDefaultInstance(props
, null);
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
);
53 } catch (AddressException e
) {
54 System
.out
.println(e
.getMessage());
55 } catch (MessagingException e
) {
56 System
.out
.println(e
.getMessage());