当前位置: 首页>>代码示例>>Java>>正文


Java Address类代码示例

本文整理汇总了Java中javax.mail.Address的典型用法代码示例。如果您正苦于以下问题:Java Address类的具体用法?Java Address怎么用?Java Address使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Address类属于javax.mail包,在下文中一共展示了Address类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFrom

import javax.mail.Address; //导入依赖的package包/类
public static String getFrom(MimeMessage msg) throws MessagingException,
        UnsupportedEncodingException {
    String from = "";
    Address[] froms = msg.getFrom();

    if (froms.length < 1) {
        throw new MessagingException("没有发件人!");
    }

    InternetAddress address = (InternetAddress) froms[0];
    String person = address.getPersonal();

    if (person != null) {
        person = MimeUtility.decodeText(person) + " ";
    } else {
        person = "";
    }

    from = person + "<" + address.getAddress() + ">";

    return from;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:23,代码来源:JavamailService.java

示例2: toAddresses

import javax.mail.Address; //导入依赖的package包/类
/**
 * 
 * @param tos address String array
 * @return Address Array
 * @throws AddressException address convert exception
 */
protected Address[] toAddresses(final String tos) throws AddressException {
    if(tos != null && !"".equals(tos)) {
        final List<Address> to = Lists.newArrayList();
        final String[] toArray = tos.split(";");
        if(ArrayUtils.isNotEmpty(toArray)) {
            for(final String address : toArray) {
                if(StringUtils.isNotBlank(address)) {
                    to.add(new InternetAddress(address.trim()));
                }
            }
        }
        
        return to.toArray(new InternetAddress[0]);
    }
    
    return null;
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:24,代码来源:AbstractMailSenderFactory.java

示例3: dispatchAnonymousMessage

import javax.mail.Address; //导入依赖的package包/类
private void dispatchAnonymousMessage() throws AddressException, MessagingException {
	int sendDelay = this.config.getInt(ConfigKeys.MAIL_SMTP_DELAY);

	for (User user : this.users) {
		if (StringUtils.isEmpty(user.getEmail())) {
			continue;
		}

		if (this.needCustomization) {
			this.defineUserMessage(user);
		}

		Address address = new InternetAddress(user.getEmail());

		if (logger.isTraceEnabled()) {
			logger.trace("Sending mail to: " + user.getEmail());
		}

		this.message.setRecipient(Message.RecipientType.TO, address);
		Transport.send(this.message, new Address[] { address });

		if (sendDelay > 0) {
			this.waitUntilNextMessage(sendDelay);
		}
	}
}
 
开发者ID:eclipse123,项目名称:JForum,代码行数:27,代码来源:Spammer.java

示例4: buildContentModelMessage

import javax.mail.Address; //导入依赖的package包/类
/**
 * This method builds {@link MimeMessage} based on {@link ContentModel}
 * 
 * @throws MessagingException
 */
private void buildContentModelMessage() throws MessagingException
{
    Map<QName, Serializable> properties = messageFileInfo.getProperties();
    String prop = null;
    setSentDate(messageFileInfo.getModifiedDate());
    // Add FROM address
    Address[] addressList = buildSenderFromAddress();
    addFrom(addressList);
    // Add TO address
    addressList = buildRecipientToAddress();
    addRecipients(RecipientType.TO, addressList);
    prop = (String) properties.get(ContentModel.PROP_TITLE);
    try
    {
        prop = (prop == null || prop.equals("")) ? messageFileInfo.getName() : prop;
        prop = MimeUtility.encodeText(prop, AlfrescoImapConst.UTF_8, null);
    }
    catch (UnsupportedEncodingException e)
    {
        // ignore
    }
    setSubject(prop);
    setContent(buildContentModelMultipart());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:ContentModelMessage.java

示例5: sendTextEmail

import javax.mail.Address; //导入依赖的package包/类
public static void sendTextEmail(String to, String from, String subject, String msg, final ServerSetup setup) {
    try {
        Session session = getSession(setup);

        Address[] tos = new javax.mail.Address[0];
        tos = new InternetAddress[]{new InternetAddress(to)};
        Address[] froms = new InternetAddress[]{new InternetAddress(from)};
        MimeMessage mimeMessage = new MimeMessage(session);
        mimeMessage.setSubject(subject);
        mimeMessage.setFrom(froms[0]);

        mimeMessage.setText(msg);
        Transport.send(mimeMessage, tos);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:18,代码来源:GreenMailUtil.java

示例6: getRecipients

import javax.mail.Address; //导入依赖的package包/类
/**
 * Get the recipients of the specified type
 *
 * @param recipientType
 *            the type of recipient - to, cc or bcc
 * @return array with recipients, emtpy array of no recipients of this type
 *         are present
 * @throws PackageException
 */
@PublicAtsApi
public String[] getRecipients(
                               RecipientType recipientType ) throws PackageException {

    try {
        Address[] recipientAddresses = message.getRecipients(recipientType.toJavamailType());

        // return an empty string if no recipients are present
        if (recipientAddresses == null) {
            return new String[]{};
        }

        String[] recipients = new String[recipientAddresses.length];
        for (int i = 0; i < recipientAddresses.length; i++) {
            recipients[i] = recipientAddresses[i].toString();
        }

        return recipients;

    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:33,代码来源:MimePackage.java

示例7: getSenderAddress

import javax.mail.Address; //导入依赖的package包/类
/**
 * This method resturns only the email address portion of the sender
 * contained in the first From header
 *
 * @return the sender address
 * @throws PackageException
 */
@PublicAtsApi
public String getSenderAddress() throws PackageException {

    try {
        Address[] fromAddresses = message.getFrom();
        if (fromAddresses == null || fromAddresses.length == 0) {
            throw new PackageException("Sender not present");
        }

        InternetAddress fromAddress = (InternetAddress) fromAddresses[0];
        return fromAddress.getAddress();

    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:24,代码来源:MimePackage.java

示例8: _getAddressString

import javax.mail.Address; //导入依赖的package包/类
/**
 * Given Address[], return a comma-separated string of the email addresses.
 * @param replyToAddresses
 * @return return a comma-separated string of the email addresses.
 */
private String _getAddressString(Address[] replyToAddresses)
{

  StringBuffer to = new StringBuffer(100);

  for (int i = 0; i < replyToAddresses.length; i++)
  {
    if (i > 0)
      to.append(",");
    to.append(((InternetAddress)replyToAddresses[i]).getAddress());
  }

  return to.toString();

}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:21,代码来源:ReplyToMessageBackingBean.java

示例9: process

import javax.mail.Address; //导入依赖的package包/类
@Override
public String process() {
	logger.info("Running inside MailBatchlet batchlet ");
	String fromAddress = stepContext.getProperties().getProperty("mail.from");
	String toAddress = stepContext.getProperties().getProperty("mail.to");

	try {
		MimeMessage m = new MimeMessage(mailSession);
		Address from = new InternetAddress(fromAddress);
		Address[] to = new InternetAddress[] { new InternetAddress(toAddress) };

		m.setFrom(from);
		m.setRecipients(TO, to);
		m.setSubject("Batch on wildfly executed");
		m.setSentDate(new java.util.Date());
		m.setContent("Job Execution id " + jobContext.getExecutionId() + " warned disk space getting low!",
				"text/plain");
		send(m);

	} catch (javax.mail.MessagingException e) {
		logger.log(SEVERE, "error send mail", e);

	}
	return COMPLETED.name();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:26,代码来源:MailBatchlet.java

示例10: sendMessage

import javax.mail.Address; //导入依赖的package包/类
@Override
public void sendMessage(Message msg, Address[] addresses)
        throws MessagingException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        msg.writeTo(out);
        lastMail = new String(out.toByteArray(), "UTF-8");
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:Transport.java

示例11: register

import javax.mail.Address; //导入依赖的package包/类
@Test
public void register() throws Exception {
    mockMvc.perform(
            post(URL_REGISTRATION)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(asJsonString(new RequestUserDTO(USERNAME, EMAIL_TO, ""))))
            .andExpect(status().isOk());

    MimeMessage[] receivedMessages = testSmtp.getReceivedMessages();
    assertEquals(1, receivedMessages.length);
    MimeMessage message = receivedMessages[0];
    assertEquals(EmailSenderImpl.SUBJECT, message.getSubject());
    String body = GreenMailUtil.getBody(message).replaceAll("=\r?\n", "");
    Address to = message.getAllRecipients()[0];
    Address from = message.getFrom()[0];
    assertEquals(EMAIL_TO, to.toString());
    assertEquals(EmailSenderImpl.EMAIL_FROM, from.toString());
    String url = TestUtils.extractLink(body);
    mockMvc.perform(get(url))
            .andExpect(status().isOk());

}
 
开发者ID:egch,项目名称:sushi-bar-BE,代码行数:23,代码来源:RegistrationControllerTest.java

示例12: getParyInfoFromEmailAddress

import javax.mail.Address; //导入依赖的package包/类
private static Map<String, Object> getParyInfoFromEmailAddress(Address [] addresses, GenericValue userLogin, LocalDispatcher dispatcher) throws GenericServiceException {
    InternetAddress emailAddress = null;
    Map<String, Object> map = null;
    Map<String, Object> result = null;

    if (addresses == null) {
        return null;
    }

    if (addresses.length > 0) {
        Address addr = addresses[0];
        if (addr instanceof InternetAddress) {
            emailAddress = (InternetAddress)addr;
        }
    }

    if (emailAddress != null) {
        map = new HashMap<String, Object>();
        map.put("address", emailAddress.getAddress());
        map.put("userLogin", userLogin);
        result = dispatcher.runSync("findPartyFromEmailAddress", map);
    }

    return result;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:26,代码来源:CommunicationEventServices.java

示例13: buildListOfPartyInfoFromEmailAddresses

import javax.mail.Address; //导入依赖的package包/类
private static List<Map<String, Object>> buildListOfPartyInfoFromEmailAddresses(Address [] addresses, GenericValue userLogin, LocalDispatcher dispatcher) throws GenericServiceException {
    InternetAddress emailAddress = null;
    Map<String, Object> result = null;
    List<Map<String, Object>> tempResults = new LinkedList<Map<String,Object>>();

    if (addresses != null) {
        for (Address addr: addresses) {
            if (addr instanceof InternetAddress) {
                emailAddress = (InternetAddress)addr;

                if (emailAddress != null) {
                    result = dispatcher.runSync("findPartyFromEmailAddress",
                            UtilMisc.toMap("address", emailAddress.getAddress(), "userLogin", userLogin));
                    if (result.get("partyId") != null) {
                        tempResults.add(result);
                    }
                }
            }
        }
    }
    return tempResults;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:23,代码来源:CommunicationEventServices.java

示例14: shouldRedirectMessage

import javax.mail.Address; //导入依赖的package包/类
@Test
public void shouldRedirectMessage() throws Exception {

    Session session = Session.getInstance(new Properties());
    doReturn(session).when(mailSenderSpy).getMailSession();

    Message messageMock = mock(Message.class);
    doReturn(messageMock).when(mailSenderSpy).initializeMimeMessage(MAIL_BODY, session);
    doReturn(SENDER_FROM).when(mailSenderSpy).getSenderFrom();

    mailSenderSpy.redirectMessage(RECIPIENT, MAIL_BODY);

    InOrder inOrder = inOrder(messageMock, mailSenderSpy);
    inOrder.verify(messageMock).setRecipients(TO, new Address[] {});
    inOrder.verify(messageMock).setRecipients(CC, new Address[] {});
    inOrder.verify(messageMock).setRecipients(BCC, new Address[] {});
    inOrder.verify(messageMock).setRecipients(TO, InternetAddress.parse(RECIPIENT));
    inOrder.verify(messageMock).setFrom(InternetAddress.parse(SENDER_FROM)[0]);

    inOrder.verify(mailSenderSpy).sendMessage(messageMock);

}
 
开发者ID:SpartaSystems,项目名称:holdmail,代码行数:23,代码来源:OutgoingMailSenderTest.java

示例15: send

import javax.mail.Address; //导入依赖的package包/类
public void send(Mail mail) throws MailerException {
	Session session = this.criarSession();

	MimeMessage message = new MimeMessage(session);

	MailTemplate template = new MailTemplateVelocity(mail);

	try {
		message.setFrom(new InternetAddress(this.getConfig().getRemetente()));
		Address[] toUser = InternetAddress.parse(mail.getDestinatario());
		message.setRecipients(Message.RecipientType.TO, toUser);
		message.setSubject(mail.getAssunto());
		message.setContent(template.getHtml(), "text/html");
		Transport.send(message);
	} catch (Exception e) {
		throw new MailerException(String.format("Erro ao enviar email: %s", e.getMessage()), e);
	}

}
 
开发者ID:marcelothebuilder,项目名称:webpedidos,代码行数:20,代码来源:Mailer.java


注:本文中的javax.mail.Address类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。