當前位置: 首頁>>代碼示例>>Java>>正文


Java SendFailedException類代碼示例

本文整理匯總了Java中javax.mail.SendFailedException的典型用法代碼示例。如果您正苦於以下問題:Java SendFailedException類的具體用法?Java SendFailedException怎麽用?Java SendFailedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SendFailedException類屬於javax.mail包,在下文中一共展示了SendFailedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendMessage

import javax.mail.SendFailedException; //導入依賴的package包/類
public void sendMessage (Message oMsg,
                         Address[] aAdrFrom, Address[] aAdrReply,
                         Address[] aAdrTo, Address[] aAdrCc, Address[] aAdrBcc)
  throws NoSuchProviderException,SendFailedException,ParseException,
         MessagingException,NullPointerException {           	
  oMsg.addFrom(aAdrFrom);
  if (null==aAdrReply)
    oMsg.setReplyTo(aAdrReply);
  else
    oMsg.setReplyTo(aAdrFrom);
  if (aAdrTo!=null) oMsg.addRecipients(javax.mail.Message.RecipientType.TO, aAdrTo);
  if (aAdrCc!=null) oMsg.addRecipients(javax.mail.Message.RecipientType.CC, aAdrCc);
  if (aAdrBcc!=null) oMsg.addRecipients(javax.mail.Message.RecipientType.BCC, aAdrBcc);
  oMsg.setSentDate(new java.util.Date());
  Transport.send(oMsg);
}
 
開發者ID:sergiomt,項目名稱:zesped,代碼行數:17,代碼來源:MailSessionHandler.java

示例2: sendEmail

import javax.mail.SendFailedException; //導入依賴的package包/類
@Asynchronous
public void sendEmail(String to, Message.RecipientType recipientType,
    String subject, String body) throws
    MessagingException, SendFailedException {

  MimeMessage message = new MimeMessage(mailSession);
  message.setFrom(new InternetAddress(mailSession.getProperty("mail.from")));
  InternetAddress[] address = {new InternetAddress(to)};
  message.setRecipients(recipientType, address);
  message.setSubject(subject);
  message.setContent(body, "text/html");

  // set the timestamp
  message.setSentDate(new Date());

  message.setText(body);
  try {
    Transport.send(message);
  } catch (MessagingException ex) {
    LOG.log(Level.SEVERE, ex.getMessage(), ex);
  }
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:23,代碼來源:EmailBean.java

示例3: showFailedException

import javax.mail.SendFailedException; //導入依賴的package包/類
/**
 * Show the error list from the e-mail API if there are errors
 *
 * @param parent
 * @param sfe
 */
private void showFailedException(SendFailedException sfe) {

   String error = sfe.getMessage() + "\n";

   Address[] ia = sfe.getInvalidAddresses();

   if (ia != null) {
      for (int x = 0; x < ia.length; x++) {
         error += "Invalid Address: " + ia[x].toString() + "\n";
      }
   }

   JTextArea ea = new JTextArea(error,6,50);
   JScrollPane errorScrollPane = new JScrollPane(ea);
   errorScrollPane.setHorizontalScrollBarPolicy(
   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
   errorScrollPane.setVerticalScrollBarPolicy(
   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
   JOptionPane.showMessageDialog(null,
                                    errorScrollPane,
                                    LangTool.getString("em.titleConfirmation"),
                                    JOptionPane.ERROR_MESSAGE);


}
 
開發者ID:tn5250j,項目名稱:tn5250j,代碼行數:32,代碼來源:SendEMail.java

示例4: handleMessagingException

import javax.mail.SendFailedException; //導入依賴的package包/類
private String handleMessagingException(Exception e) {
    StringBuffer exmess = new StringBuffer();
    do {
        if (e instanceof SendFailedException) {
            SendFailedException sfex = (SendFailedException)e;
            Address[] invalid = sfex.getInvalidAddresses();               
            if (invalid != null) {
                exmess.append("\n    ** Invalid Addresses");
                if (invalid != null) {
                    for (int i = 0; i < invalid.length; i++)
                        exmess.append("         " + invalid[i]);
                }
            }
            Address[] validUnsent = sfex.getValidUnsentAddresses();
            if (validUnsent != null) {
                exmess.append("\n    ** ValidUnsent Addresses");
                if (validUnsent != null) {
                    for (int i = 0; i < validUnsent.length; i++)
                        exmess.append("         "+validUnsent[i]);
                }
            }
            Address[] validSent = sfex.getValidSentAddresses();
            if (validSent != null) {
                exmess.append("\n    ** ValidSent Addresses");
                if (validSent != null) {
                    for (int i = 0; i < validSent.length; i++)
                        exmess.append("         "+validSent[i]);
                }
            }
        }
        if (e instanceof MessagingException)
            e = ((MessagingException)e).getNextException();
        else
            e = null;
    } while (e != null);
    return exmess.toString();
}
 
開發者ID:NOAA-PMEL,項目名稱:LAS,代碼行數:38,代碼來源:ProductServerRunner.java

示例5: sendEmails

import javax.mail.SendFailedException; //導入依賴的package包/類
@Asynchronous
public void sendEmails(String listAddrs, String subject, String body) throws MessagingException, SendFailedException {

  List<String> addrs = Arrays.asList(listAddrs.split("\\s*,\\s*"));

  boolean first = false;
  MimeMessage message = new MimeMessage(mailSession);
  message.setFrom(new InternetAddress(mailSession.getProperty("mail.from")));
  message.setSubject(subject);
  message.setContent(body, "text/html");
  message.setSentDate(new Date());
  message.setText(body);
  for (String addr : addrs) {

    InternetAddress[] address = {new InternetAddress(addr)};
    if (first) {
      message.setRecipients(Message.RecipientType.TO, address);
      first = false;
    } else {
      message.setRecipients(Message.RecipientType.CC, address);
    }

  }
  try {
    Transport.send(message);
  } catch (MessagingException ex) {
    LOG.log(Level.SEVERE, ex.getMessage(), ex);
  }
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:30,代碼來源:EmailBean.java

示例6: handleSendFailedException

import javax.mail.SendFailedException; //導入依賴的package包/類
/**
 * handles the sendFailedException
 * <p>
 * creates a MessageSendStatus which contains a translateable info or error message, and the knowledge if the user can proceed with its action. 
 * 
 * @param e
 * @throws OLATRuntimeException return MessageSendStatus
 */
private MessageSendStatus handleSendFailedException(final SendFailedException e) {
	// get wrapped excpetion
	MessageSendStatus messageSendStatus = null;
	
	final MessagingException me = (MessagingException) e.getNextException();
	if (me instanceof AuthenticationFailedException) {
		messageSendStatus = createAuthenticationFailedMessageSendStatus();
		return messageSendStatus;
	}
	
	final String message = me.getMessage();
	if (message.startsWith("553")) {
		messageSendStatus = createInvalidDomainMessageSendStatus();
	} else if (message.startsWith("Invalid Addresses")) {
		messageSendStatus = createInvalidAddressesMessageSendStatus(e.getInvalidAddresses());
	} else if (message.startsWith("503 5.0.0")) {
		messageSendStatus = createNoRecipientMessageSendStatus();
	} else if (message.startsWith("Unknown SMTP host")) {
		messageSendStatus = createUnknownSMTPHost();
	} else if (message.startsWith("Could not connect to SMTP host")) {
		messageSendStatus = createCouldNotConnectToSmtpHostMessageSendStatus();
	} else {
		List<ContactList> emailToContactLists = getTheToContactLists();
		String exceptionMessage = "";
		for (ContactList contactList : emailToContactLists) {
			exceptionMessage += contactList.toString();
		}
		throw new OLATRuntimeException(ContactUIModel.class, exceptionMessage, me);
	}
	return messageSendStatus;
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:40,代碼來源:ExceptionHandlingMailSendingTemplate.java

示例7: sendEmail

import javax.mail.SendFailedException; //導入依賴的package包/類
private boolean sendEmail(String from, String mailto, String subject, String body) throws AddressException, SendFailedException, MessagingException {

		if (webappAndMailHelper.isEmailFunctionalityDisabled()) return false;
		
		InternetAddress mailFromAddress = new InternetAddress(from);
		InternetAddress mailToAddress[] = InternetAddress.parse(mailto);
        MailerResult result = new MailerResult();
		
		MimeMessage msg = webappAndMailHelper.createMessage(mailFromAddress, mailToAddress, null, null, body + footer, subject, null, result);
		webappAndMailHelper.send(msg, result);
		//TODO:discuss why is the MailerResult not used here?
        return true;
    }
 
開發者ID:huihoo,項目名稱:olat,代碼行數:14,代碼來源:Emailer.java

示例8: testSendWithoutException

import javax.mail.SendFailedException; //導入依賴的package包/類
@Test
public void testSendWithoutException() {
	//setup
	ExceptionHandlingMailSendingTemplate doSendWithoutException = new ExceptionHandlingMailSendingTemplate() {
		

		@Override
		protected boolean doSend(Emailer emailer) throws AddressException, SendFailedException, MessagingException {
			assertNotNull("emailer was constructed", emailer);
			return true;
		}
		
		@Override
		protected MailTemplate getMailTemplate() {
			return emptyMailTemplate;
		};
		
		@Override
		protected List<ContactList> getTheToContactLists() {
			return theContactLists;
		}
		
		@Override
		protected Identity getFromIdentity() {
			return theFromIdentity;
		}
	};
	
	//exercise
	MessageSendStatus sendStatus = doSendWithoutException.send();
	
	//verify
	assertEquals(MessageSendStatusCode.SUCCESSFULL_SENT_EMAILS, sendStatus.getStatusCode());
	assertTrue(sendStatus.getStatusCode().isSuccessfullSentMails());
	assertFalse(sendStatus.isSeverityError());
	assertFalse(sendStatus.isSeverityWarn());
	assertTrue(sendStatus.canProceedWithWorkflow());
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:39,代碼來源:ExceptionHandlingMailSendingTemplateTest.java

示例9: shouldFailWithAddressExcpetion

import javax.mail.SendFailedException; //導入依賴的package包/類
@Test
public void shouldFailWithAddressExcpetion(){
	//setup
	ExceptionHandlingMailSendingTemplate doSendWithAddressException = new ExceptionHandlingMailSendingTemplate() {
					@Override
		protected boolean doSend(Emailer emailer) throws AddressException, SendFailedException, MessagingException {
			assertNotNull("emailer was constructed", emailer);
			throw new AddressException();
		}
		
		@Override
		protected MailTemplate getMailTemplate() {
			return emptyMailTemplate;
		};
		
		@Override
		protected List<ContactList> getTheToContactLists() {
			return theContactLists;
		}
		
		@Override
		protected Identity getFromIdentity() {
			return theFromIdentity;
		}
	};
	
	//exercise
	MessageSendStatus sendStatus = doSendWithAddressException.send();
	
	//verify
	assertEquals(MessageSendStatusCode.SENDER_OR_RECIPIENTS_NOK_553, sendStatus.getStatusCode());
	verifyStatusCodeIndicateAddressExceptionOnly(sendStatus);
	verifySendStatusIsWarn(sendStatus);
	assertFalse(sendStatus.canProceedWithWorkflow());	
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:36,代碼來源:ExceptionHandlingMailSendingTemplateTest.java

示例10: shouldFailWithSendFailedExceptionWithDomainErrorCode553

import javax.mail.SendFailedException; //導入依賴的package包/類
@Test
public void shouldFailWithSendFailedExceptionWithDomainErrorCode553(){
	//setup
	ExceptionHandlingMailSendingTemplate doSendWithSendFailedException = new ExceptionHandlingMailSendingTemplate() {
		@Override
		protected boolean doSend(Emailer emailer) throws AddressException, SendFailedException, MessagingException {
			assertNotNull("emailer was constructed", emailer);
			MessagingException firstInnerException = new SendFailedException("553 some domain error message from the mailsystem");
			throw new SendFailedException(BY_OLAT_UNHANDLED_TEXT, firstInnerException);
		}
		
		@Override
		protected MailTemplate getMailTemplate() {
			return emptyMailTemplate;
		};
		
		@Override
		protected List<ContactList> getTheToContactLists() {
			return theContactLists;
		}
		
		@Override
		protected Identity getFromIdentity() {
			return theFromIdentity;
		}
	};
	
	//exercise
	MessageSendStatus sendStatus = doSendWithSendFailedException.send();
	
	//verify
	assertEquals(MessageSendStatusCode.SEND_FAILED_DUE_INVALID_DOMAIN_NAME_553, sendStatus.getStatusCode());
	verifyStatusCodeIndicateSendFailedOnly(sendStatus);
	verifySendStatusIsError(sendStatus);
	assertFalse(sendStatus.canProceedWithWorkflow());
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:37,代碼來源:ExceptionHandlingMailSendingTemplateTest.java

示例11: shouldFailWithSendFailedExceptionWithInvalidAddresses

import javax.mail.SendFailedException; //導入依賴的package包/類
@Test
public void shouldFailWithSendFailedExceptionWithInvalidAddresses(){
	//setup
	ExceptionHandlingMailSendingTemplate doSendWithSendFailedException = new ExceptionHandlingMailSendingTemplate() {
		@Override
		protected boolean doSend(Emailer emailer) throws AddressException, SendFailedException, MessagingException {
			assertNotNull("emailer was constructed", emailer);
			MessagingException firstInnerException = new SendFailedException("Invalid Addresses <followed by a list of invalid addresses>");
			throw new SendFailedException(BY_OLAT_UNHANDLED_TEXT, firstInnerException);
		}
		
		@Override
		protected MailTemplate getMailTemplate() {
			return emptyMailTemplate;
		};
		
		@Override
		protected List<ContactList> getTheToContactLists() {
			return theContactLists;
		}
		
		@Override
		protected Identity getFromIdentity() {
			return theFromIdentity;
		}
	};
	
	//exercise
	MessageSendStatus sendStatus = doSendWithSendFailedException.send();
	
	//verify
	assertEquals(MessageSendStatusCode.SEND_FAILED_DUE_INVALID_ADDRESSES_550, sendStatus.getStatusCode());
	verifyStatusCodeIndicateSendFailedOnly(sendStatus);
	verifySendStatusIsError(sendStatus);
	assertFalse(sendStatus.canProceedWithWorkflow());
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:37,代碼來源:ExceptionHandlingMailSendingTemplateTest.java

示例12: shouldFailWithSendFailedExceptionBecauseNoRecipient

import javax.mail.SendFailedException; //導入依賴的package包/類
@Test
public void shouldFailWithSendFailedExceptionBecauseNoRecipient(){
	//setup
	ExceptionHandlingMailSendingTemplate doSendWithSendFailedException = new ExceptionHandlingMailSendingTemplate() {
		@Override
		protected boolean doSend(Emailer emailer) throws AddressException, SendFailedException, MessagingException {
			assertNotNull("emailer was constructed", emailer);
			MessagingException firstInnerException = new SendFailedException("503 5.0.0 .... ");
			throw new SendFailedException(BY_OLAT_UNHANDLED_TEXT, firstInnerException);
		}
		
		@Override
		protected MailTemplate getMailTemplate() {
			return emptyMailTemplate;
		};
		
		@Override
		protected List<ContactList> getTheToContactLists() {
			return theContactLists;
		}
		
		@Override
		protected Identity getFromIdentity() {
			return theFromIdentity;
		}
	};
	
	//exercise
	MessageSendStatus sendStatus = doSendWithSendFailedException.send();
	
	//verify
	assertEquals(MessageSendStatusCode.SEND_FAILED_DUE_NO_RECIPIENTS_503, sendStatus.getStatusCode());
	verifyStatusCodeIndicateSendFailedOnly(sendStatus);
	verifySendStatusIsError(sendStatus);
	assertFalse(sendStatus.canProceedWithWorkflow());
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:37,代碼來源:ExceptionHandlingMailSendingTemplateTest.java

示例13: shouldFailWithSendFailedExceptionBecauseUnknownSMTPHost

import javax.mail.SendFailedException; //導入依賴的package包/類
@Test
public void shouldFailWithSendFailedExceptionBecauseUnknownSMTPHost(){
	//setup
	ExceptionHandlingMailSendingTemplate doSendWithSendFailedException = new ExceptionHandlingMailSendingTemplate() {
		@Override
		protected boolean doSend(Emailer emailer) throws AddressException, SendFailedException, MessagingException {
			assertNotNull("emailer was constructed", emailer);
			MessagingException firstInnerException = new SendFailedException("Unknown SMTP host");
			throw new SendFailedException(BY_OLAT_UNHANDLED_TEXT, firstInnerException);
		}
		
		@Override
		protected MailTemplate getMailTemplate() {
			return emptyMailTemplate;
		};
		
		@Override
		protected List<ContactList> getTheToContactLists() {
			return theContactLists;
		}
		
		@Override
		protected Identity getFromIdentity() {
			return theFromIdentity;
		}
	};
	
	//exercise
	MessageSendStatus sendStatus = doSendWithSendFailedException.send();
	
	//verify
	assertEquals(MessageSendStatusCode.SEND_FAILED_DUE_UNKNOWN_SMTP_HOST, sendStatus.getStatusCode());
	verifyStatusCodeIndicateSendFailedOnly(sendStatus);
	verifySendStatusIsError(sendStatus);
	assertTrue(sendStatus.canProceedWithWorkflow());
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:37,代碼來源:ExceptionHandlingMailSendingTemplateTest.java

示例14: shouldFailWithSendFailedExceptionBecauseCouldNotConnectToSMTPHost

import javax.mail.SendFailedException; //導入依賴的package包/類
@Test
public void shouldFailWithSendFailedExceptionBecauseCouldNotConnectToSMTPHost(){
	//setup
	ExceptionHandlingMailSendingTemplate doSendWithSendFailedException = new ExceptionHandlingMailSendingTemplate() {
		@Override
		protected boolean doSend(Emailer emailer) throws AddressException, SendFailedException, MessagingException {
			assertNotNull("emailer was constructed", emailer);
			MessagingException firstInnerException = new SendFailedException("Could not connect to SMTP host");
			throw new SendFailedException(BY_OLAT_UNHANDLED_TEXT, firstInnerException);
		}
		
		@Override
		protected MailTemplate getMailTemplate() {
			return emptyMailTemplate;
		};
		
		@Override
		protected List<ContactList> getTheToContactLists() {
			return theContactLists;
		}
		
		@Override
		protected Identity getFromIdentity() {
			return theFromIdentity;
		}
	};
	
	//exercise
	MessageSendStatus sendStatus = doSendWithSendFailedException.send();
	
	//verify
	assertEquals(MessageSendStatusCode.SEND_FAILED_DUE_COULD_NOT_CONNECT_TO_SMTP_HOST, sendStatus.getStatusCode());
	verifyStatusCodeIndicateSendFailedOnly(sendStatus);
	verifySendStatusIsError(sendStatus);
	assertTrue(sendStatus.canProceedWithWorkflow());
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:37,代碼來源:ExceptionHandlingMailSendingTemplateTest.java

示例15: shouldFailWithSendFailedExceptionWithAnAuthenticationFailedException

import javax.mail.SendFailedException; //導入依賴的package包/類
@Test
public void shouldFailWithSendFailedExceptionWithAnAuthenticationFailedException(){
	//setup
	ExceptionHandlingMailSendingTemplate doSendWithSendFailedException = new ExceptionHandlingMailSendingTemplate() {
		@Override
		protected boolean doSend(Emailer emailer) throws AddressException, SendFailedException, MessagingException {
			assertNotNull("emailer was constructed", emailer);
			MessagingException firstInnerException = new AuthenticationFailedException("<some authentication failed message from the mailsystem>");
			throw new SendFailedException(BY_OLAT_UNHANDLED_TEXT, firstInnerException);
		}
		
		@Override
		protected MailTemplate getMailTemplate() {
			return emptyMailTemplate;
		};
		
		@Override
		protected List<ContactList> getTheToContactLists() {
			return theContactLists;
		}
		
		@Override
		protected Identity getFromIdentity() {
			return theFromIdentity;
		}
	};	
	
	//exercise
	MessageSendStatus sendStatus = doSendWithSendFailedException.send();
	
	//verify
	assertEquals(MessageSendStatusCode.SMTP_AUTHENTICATION_FAILED, sendStatus.getStatusCode());
	verifyStatusCodeIndicateSendFailedOnly(sendStatus);
	verifySendStatusIsError(sendStatus);
	assertTrue(sendStatus.canProceedWithWorkflow());
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:37,代碼來源:ExceptionHandlingMailSendingTemplateTest.java


注:本文中的javax.mail.SendFailedException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。