This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a410e4
commit 519b8db
Showing
8 changed files
with
145 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
feilong-net-mail/src/main/java/com/feilong/net/mail/RecipientsSetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) 2008 feilong | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.feilong.net.mail; | ||
|
||
import static com.feilong.core.Validator.isNotNullOrEmpty; | ||
|
||
import javax.mail.Message; | ||
import javax.mail.MessagingException; | ||
|
||
import com.feilong.net.mail.entity.MailSenderConfig; | ||
import com.feilong.net.mail.util.InternetAddressUtil; | ||
|
||
/** | ||
* The Class RecipientsSetter. | ||
* | ||
* @author <a href="http://feitianbenyue.iteye.com/">feilong</a> | ||
* @since 1.13.2 | ||
*/ | ||
public final class RecipientsSetter{ | ||
|
||
/** | ||
* 设置邮件接受人群. | ||
* | ||
* <p> | ||
* 支持 to cc bcc. | ||
* </p> | ||
* | ||
* @param message | ||
* the message | ||
* @param mailSenderConfig | ||
* the new recipients | ||
* @throws MessagingException | ||
* the messaging exception | ||
*/ | ||
public static void setRecipients(Message message,MailSenderConfig mailSenderConfig) throws MessagingException{ | ||
// 创建邮件的接收者地址,并设置到邮件消息中 | ||
// Message.RecipientType.TO属性表示接收者的类型为TO | ||
String[] tos = mailSenderConfig.getTos(); | ||
if (isNotNullOrEmpty(tos)){ | ||
message.setRecipients(Message.RecipientType.TO, InternetAddressUtil.toAddressArray(tos)); | ||
} | ||
|
||
//--------------------------------------------------------------- | ||
|
||
//cc 抄送 | ||
String[] ccs = mailSenderConfig.getCcs(); | ||
if (isNotNullOrEmpty(ccs)){ | ||
message.setRecipients(Message.RecipientType.CC, InternetAddressUtil.toAddressArray(ccs)); | ||
} | ||
|
||
//--------------------------------------------------------------- | ||
|
||
//bcc 密送 | ||
String[] bccs = mailSenderConfig.getBccs(); | ||
if (isNotNullOrEmpty(bccs)){ | ||
message.setRecipients(Message.RecipientType.BCC, InternetAddressUtil.toAddressArray(bccs)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.