本文整理汇总了Java中com.sun.mail.smtp.SMTPMessage.writeTo方法的典型用法代码示例。如果您正苦于以下问题:Java SMTPMessage.writeTo方法的具体用法?Java SMTPMessage.writeTo怎么用?Java SMTPMessage.writeTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.mail.smtp.SMTPMessage
的用法示例。
在下文中一共展示了SMTPMessage.writeTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}