本文整理汇总了Java中com.sun.mail.smtp.SMTPMessage.setRecipients方法的典型用法代码示例。如果您正苦于以下问题:Java SMTPMessage.setRecipients方法的具体用法?Java SMTPMessage.setRecipients怎么用?Java SMTPMessage.setRecipients使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.mail.smtp.SMTPMessage
的用法示例。
在下文中一共展示了SMTPMessage.setRecipients方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: composeMessage
import com.sun.mail.smtp.SMTPMessage; //导入方法依赖的package包/类
/**
* Helper method for composing a simple text MIME Message with the source.
* If from address is null, will use the internet address of the local host.
*
* @param source
* @return
* @throws SmtpMailException
*/
private SMTPMessage composeMessage(String source, Address from,
Address[] to, String subject) throws SmtpMailException {
SMTPMessage msg = new SMTPMessage(session);
try {
if (from == null) {
msg.setFrom();
} else {
msg.setFrom(from);
}
msg.setSubject(subject);
msg.setRecipients(Message.RecipientType.TO, to);
msg.setText(source);
msg.setSentDate(new Date());
return msg;
} catch (MessagingException e) {
throw new SmtpMailException("Error creating the message.", e);
}
}
示例2: testCaseSensitivity
import com.sun.mail.smtp.SMTPMessage; //导入方法依赖的package包/类
/**
* MNT-9289
*
* Change in case in email Subject causes DuplicateChildNodeNameException
*/
public void testCaseSensitivity() throws Exception
{
NodeRef person = personService.getPerson(TEST_USER);
String TEST_EMAIL="[email protected]";
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
if(person == null)
{
logger.debug("new person created");
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_USERNAME, TEST_USER);
props.put(ContentModel.PROP_EMAIL, TEST_EMAIL);
person = personService.createPerson(props);
}
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
if(!auths.contains(TEST_USER))
{
authorityService.addAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
}
String companyHomePathInStore = "/app:company_home";
String storePath = "workspace://SpacesStore";
StoreRef storeRef = new StoreRef(storePath);
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
NodeRef companyHomeNodeRef = nodeRefs.get(0);
assertNotNull("company home is null", companyHomeNodeRef);
String TEST_CASE_SENSITIVITY_SUBJECT = "Test (Mail)";
String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String from = TEST_EMAIL;
String to = testUserHomeDBID;
String content = "hello world";
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
EmailDelivery delivery = new EmailDelivery(to, from, null);
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
msg.setContent(content, "text/plain");
msg.setSubject(TEST_CASE_SENSITIVITY_SUBJECT);
ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
msg.writeTo(bos1);
InputStream is = IOUtils.toInputStream(bos1.toString());
assertNotNull("is is null", is);
SubethaEmailMessage m = new SubethaEmailMessage(is);
folderEmailMessageHandler.setOverwriteDuplicates(false);
emailService.importMessage(delivery, m);
QName safeQName = QName.createQNameWithValidLocalName(NamespaceService.CONTENT_MODEL_1_0_URI, TEST_CASE_SENSITIVITY_SUBJECT);
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, safeQName);
assertEquals(1, assocs.size());
msg.setSubject(TEST_CASE_SENSITIVITY_SUBJECT.toUpperCase());
ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
msg.writeTo(bos2);
is = IOUtils.toInputStream(bos2.toString());
assertNotNull("is is null", is);
m = new SubethaEmailMessage(is);
folderEmailMessageHandler.setOverwriteDuplicates(false);
emailService.importMessage(delivery, m);
safeQName = QName.createQNameWithValidLocalName(NamespaceService.CONTENT_MODEL_1_0_URI, TEST_CASE_SENSITIVITY_SUBJECT.toUpperCase() + "(1)");
assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, safeQName);
assertEquals(1, assocs.size());
}
示例3: setRecipients
import com.sun.mail.smtp.SMTPMessage; //导入方法依赖的package包/类
/**
* Sets recipients.
*
* <b>NOTE: If {@link IMailBL#getDebugMailToAddressOrNull(Properties)} returns a valid mail address, it will send to that instead!</b>
*
* @param message
* @param type
* @param addresses
* @throws MessagingException
*/
private void setRecipients(final SMTPMessage message, final RecipientType type, final List<? extends Address> addresses) throws MessagingException
{
if (addresses == null || addresses.isEmpty())
{
return;
}
final InternetAddress debugMailTo = Services.get(IMailBL.class).getDebugMailToAddressOrNull(Env.getCtx());
if (debugMailTo != null)
{
if (Message.RecipientType.TO.equals(type))
{
message.setRecipient(Message.RecipientType.TO, debugMailTo);
}
for (final Address address : addresses)
{
message.addHeader("X-metasfreshDebug-Original-Address" + type.toString(), address.toString());
}
}
else
{
final Address[] addressesArr = addresses.toArray(new Address[addresses.size()]);
message.setRecipients(Message.RecipientType.TO, addressesArr);
}
}