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


Java MessagingException類代碼示例

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


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

示例1: sendMail

import javax.mail.MessagingException; //導入依賴的package包/類
public static void sendMail(String host, int port, String username, String password, String recipients,
		String subject, String content, String from) throws AddressException, MessagingException {
	
	Properties props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", host);
	props.put("mail.smtp.port", port);

	Session session = Session.getInstance(props, new javax.mail.Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(username, password);
		}
	});

	Message message = new MimeMessage(session);
	message.setFrom(new InternetAddress(from));
	message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
	message.setSubject(subject);
	message.setText(content);

	Transport.send(message);
}
 
開發者ID:bndynet,項目名稱:web-framework-for-java,代碼行數:24,代碼來源:MailHelper.java

示例2: getRecipients

import javax.mail.MessagingException; //導入依賴的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

示例3: getSenderAddress

import javax.mail.MessagingException; //導入依賴的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

示例4: reconnectStoreIfClosed

import javax.mail.MessagingException; //導入依賴的package包/類
/**
 * Reconnects if connection is closed.
 * <b>Note</b>Internal method
 * @return true if store re-connection is performed and this means that close should be closed after the work is done
 * @throws MessagingException
 */
public boolean reconnectStoreIfClosed() throws MessagingException {

    boolean storeReconnected = false;

    // the folder is empty when the message is not loaded from IMAP server, but from a file
    Folder imapFolder = message.getFolder();
    if (imapFolder == null) {
        imapFolder = this.partOfImapFolder;
    } else {
        partOfImapFolder = imapFolder; // keep reference
    }
    if (imapFolder != null) {
        Store store = imapFolder.getStore();
        if (store != null) {
            if (!store.isConnected()) {
                log.debug("Reconnecting store... ");
                store.connect();
                storeReconnected = true;
            }

            // Open folder in read-only mode
            if (!imapFolder.isOpen()) {
                log.debug("Reopening folder " + imapFolder.getFullName()
                          + " in order to get contents of mail message");
                imapFolder.open(Folder.READ_ONLY);
            }
        }
    }
    return storeReconnected;
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:37,代碼來源:MimePackage.java

示例5: convert

import javax.mail.MessagingException; //導入依賴的package包/類
public Email convert(RawData rawData) throws IOException {
    try {
        Session s = Session.getDefaultInstance(new Properties());
        MimeMessage mimeMessage = new MimeMessage(s, rawData.getContentAsStream());
        String subject = Objects.toString(mimeMessage.getSubject(), UNDEFINED);
        ContentType contentType = ContentType.fromString(mimeMessage.getContentType());
        Object messageContent = mimeMessage.getContent();

        switch (contentType) {
            case HTML:
            case PLAIN:
                return buildPlainOrHtmlEmail(rawData, subject, contentType, messageContent);
            case MULTIPART_ALTERNATIVE:
                return buildMultipartAlternativeMail(rawData, subject, (Multipart) messageContent);
            default:
                throw new IllegalStateException("Unsupported e-mail content type " + contentType.name());
        }
    } catch (MessagingException e) {
        return buildFallbackEmail(rawData);
    }
}
 
開發者ID:gessnerfl,項目名稱:fake-smtp-server,代碼行數:22,代碼來源:EmailFactory.java

示例6: sendMailWithNewPassword

import javax.mail.MessagingException; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithNewPassword(
        @NotBlank @Email final String email,
        @NotBlank final String newPassword
) {
    log.info("Called with e-mail {}, newPassword {}", email, newPassword);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Recover password");
        helper.setText("Your new password: " + "<b>" + newPassword + "</b>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:28,代碼來源:MailServiceImpl.java

示例7: getAttachmentContentType

import javax.mail.MessagingException; //導入依賴的package包/類
/**
 * Get the attachment content type
 *
 * @param partIndex
 * @return
 * @throws PackageException
 */
@PublicAtsApi
public String getAttachmentContentType(
                                        int partIndex ) throws PackageException {

    // first check if there is part at this position at all
    if (partIndex >= attachmentPartIndices.size()) {
        throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
    }

    try {
        MimePart part = getPart(attachmentPartIndices.get(partIndex));

        // get the content type header
        ContentType contentType = new ContentType(part.getContentType());
        return contentType.getBaseType();
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:27,代碼來源:MimePackage.java

示例8: addAttachment

import javax.mail.MessagingException; //導入依賴的package包/類
/**
 * Add an attachment with the specified content - the attachment will have a
 * content type text\plain and the specified character set
 *
 * @param content
 *            the content of the attachment
 * @param charset
 *            the character set
 * @param fileName
 *            the file name for the content-disposition header
 * @throws PackageException
 *             on error
 */
@PublicAtsApi
public void addAttachment(
                           String content,
                           String charset,
                           String fileName ) throws PackageException {

    try {
        // add attachment to multipart content
        MimeBodyPart attPart = new MimeBodyPart();
        attPart.setText(content, charset, PART_TYPE_TEXT_PLAIN);
        attPart.setDisposition(MimeBodyPart.ATTACHMENT);
        attPart.setFileName(fileName);

        addPart(attPart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:32,代碼來源:MimePackage.java

示例9: emptyAddressBcc

import javax.mail.MessagingException; //導入依賴的package包/類
@Test( expected = MailReportSendException.class)
public void emptyAddressBcc() throws MessagingException {

    expect(ReportConfigurator.getInstance()).andReturn(mockReportConfigurator);
    expect(mockReportConfigurator.getSmtpServerName()).andReturn("localhost");
    expect(mockReportConfigurator.getSmtpServerPort()).andReturn("25");
    expect(mockReportConfigurator.getAddressesTo()).andReturn(new String[0]);
    expect(mockReportConfigurator.getAddressesCc()).andReturn(new String[0]);
    expect(mockReportConfigurator.getAddressesBcc()).andReturn(new String[]{ "" });
    expect(mockReportConfigurator.getAddressFrom()).andReturn("userFrom");

    replayAll();

    triggerRun();

    verifyAll();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:18,代碼來源:Test_MailReportSender.java

示例10: sendMail

import javax.mail.MessagingException; //導入依賴的package包/類
private void sendMail(String subject, String body, MailSettings settings) throws MessagingException {

        Properties props = new Properties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.host", settings.getSmtpServer());
        props.put("mail.smtp.port", settings.getSmtpPort() + "");

        if (settings.getMode() == MailSettings.Mode.SSL) {
            props.put("mail.smtp.socketFactory.port", settings.getSmtpPort() + "");
            props.put("mail.smtp.socketFactory.class",
                    "javax.net.ssl.SSLSocketFactory");
        } else if (settings.getMode() == MailSettings.Mode.TLS) {
            props.put("mail.smtp.starttls.enable", "true");
        }

        props.put("mail.smtp.auth", settings.isUseAuth() + "");

        Session session;
        if (settings.isUseAuth()) {
            session = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(settings.getUser(), settings.getPass());
                }
            });
        } else {
            session = Session.getInstance(props);
        }

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(settings.getFrom()));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(settings.getTo()));
        message.setSubject(subject);
        message.setText(body);

        Transport.send(message);

    }
 
開發者ID:dainesch,項目名稱:HueSense,代碼行數:41,代碼來源:MailService.java

示例11: transformRecipients

import javax.mail.MessagingException; //導入依賴的package包/類
/**
 * Transport recipients to InternetAddress array.
 *
 * @param recipients
 *            the set of all recipients
 * @return InternetAddress array of all recipients internetAddress
 * @throws MessagingException
 *             messagingException from javax.mail
 */
private InternetAddress[] transformRecipients(final Set<String> recipients) throws MessagingException {
	if (recipients.isEmpty()) {
		throw new MessagingException("recipients of mail should not be empty");
	}

	final InternetAddress[] ret = new InternetAddress[recipients.size()];
	int i = 0;

	for (String recipient : recipients) {
		ret[i] = new InternetAddress(recipient);
		i++;
	}

	return ret;
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:25,代碼來源:MailService.java

示例12: sendAttachmentsMail

import javax.mail.MessagingException; //導入依賴的package包/類
/**
 * 發送帶附件的郵件
 */
@Async("mailAsync")
public void sendAttachmentsMail(String to, String subject, String content, String filePath) {
	MimeMessage message = mailSender.createMimeMessage();
	try {
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		helper.setText(content, true);
		helper.setSentDate(new Date());
		FileSystemResource file = new FileSystemResource(new File(filePath));
		String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
		helper.addAttachment(fileName, file);
		mailSender.send(message);
		logger.info("帶附件的郵件已經發送。");
	} catch (MessagingException e) {
		logger.error("發送帶附件的郵件時發生異常!", e);
	}
}
 
開發者ID:CharleyXu,項目名稱:tulingchat,代碼行數:23,代碼來源:MailUtil.java

示例13: compact

import javax.mail.MessagingException; //導入依賴的package包/類
public String compact() throws MessagingException
{
  Folder folder = _folderData.getFolder();
  
  folder.open(Folder.READ_WRITE);
  // It would be much more efficient to simply trim out
  // the list of "expunged" messages from the data model;
  // instead, we're refreshing the list.
  folder.expunge();
  folder.close(true);

  return refresh();
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:14,代碼來源:MessagesBackingBean.java

示例14: sendEmailWithOrder

import javax.mail.MessagingException; //導入依賴的package包/類
public static void sendEmailWithOrder(String text, String eMail, HttpServletRequest request) {
    try {
        Session session = EmailActions.authorizeWebShopEmail();

        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(eMail, false));
        msg.setSubject("Shop order");
        msg.setText(text);
        msg.setSentDate(new Date());
        Transport.send(msg);
    } catch (MessagingException e) {
        System.out.println("Error : " + e);
    }
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:16,代碼來源:SendEmailUserAccount.java

示例15: sendMail

import javax.mail.MessagingException; //導入依賴的package包/類
private void sendMail(SendMailActionMsg msg) throws MessagingException {
  log.debug("Sending mail {}", msg);
  MimeMessage mailMsg = mailSender.createMimeMessage();
  MimeMessageHelper helper = new MimeMessageHelper(mailMsg, "UTF-8");
  helper.setFrom(msg.getFrom());
  helper.setTo(msg.getTo());
  if (!StringUtils.isEmpty(msg.getCc())) {
    helper.setCc(msg.getCc());
  }
  if (!StringUtils.isEmpty(msg.getBcc())) {
    helper.setBcc(msg.getBcc());
  }
  helper.setSubject(msg.getSubject());
  helper.setText(msg.getBody());
  mailSender.send(helper.getMimeMessage());
  log.debug("Mail sent {}", msg);
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:18,代碼來源:MailPlugin.java


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