当前位置: 首页>>代码示例>>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;未经允许,请勿转载。