本文整理匯總了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;
}
示例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;
}
示例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);
}
}
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}