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


Java MimeBodyPart.setDisposition方法代码示例

本文整理汇总了Java中javax.mail.internet.MimeBodyPart.setDisposition方法的典型用法代码示例。如果您正苦于以下问题:Java MimeBodyPart.setDisposition方法的具体用法?Java MimeBodyPart.setDisposition怎么用?Java MimeBodyPart.setDisposition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.internet.MimeBodyPart的用法示例。


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

示例1: addAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public static String addAttachment(MimeMultipart mm, String path)
{
	if(count == Integer.MAX_VALUE)
	{
		count = 0;
	}
	int cid = count++;
       try
	{
   		java.io.File file = new java.io.File(path);
   		MimeBodyPart mbp = new MimeBodyPart();
   		mbp.setDisposition(MimeBodyPart.INLINE);
   		mbp.setContent(new MimeMultipart("mixed"));
   		mbp.setHeader("Content-ID", "<" + cid + ">");
		mbp.setDataHandler(new DataHandler(new FileDataSource(file)));
        mbp.setFileName(new String(file.getName().getBytes("GBK"), "ISO-8859-1"));
        mm.addBodyPart(mbp);
        return String.valueOf(cid);
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
       return "";
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:26,代码来源:EmailUtil.java

示例2: addPart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Add a part with the specified text to the specified position
 *
 * @param content the part's content
 * @param contentTypeSubtype the part's subtype of content type like plain (sub type of text/plain) or html (sub type of text/html)
 * @param charset the part's charset
 * @throws PackageException
 */
@PublicAtsApi
public void addPart(
                     String content,
                     String contentTypeSubtype,
                     String charset ) throws PackageException {

    // create a new inline part
    MimeBodyPart part = new MimeBodyPart();

    try {
        part.setText(content, charset, contentTypeSubtype);
        part.setDisposition(MimeBodyPart.INLINE);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }

    addPart(part, PART_POSITION_LAST);
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:27,代码来源:MimePackage.java

示例3: addAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Add the specified file as an attachment
 *
 * @param fileName
 *            name of the file
 * @throws PackageException
 *             on error
 */
@PublicAtsApi
public void addAttachment(
                           String fileName ) throws PackageException {

    try {
        // add attachment to multipart content
        MimeBodyPart attPart = new MimeBodyPart();
        FileDataSource ds = new FileDataSource(fileName);
        attPart.setDataHandler(new DataHandler(ds));
        attPart.setDisposition(MimeBodyPart.ATTACHMENT);
        attPart.setFileName(ds.getName());

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

示例4: part

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private static MimeBodyPart part(final ChainedHttpConfig config, final MultipartContent.MultipartPart multipartPart) throws MessagingException {
    final MimeBodyPart bodyPart = new MimeBodyPart();
    bodyPart.setDisposition("form-data");

    if (multipartPart.getFileName() != null) {
        bodyPart.setFileName(multipartPart.getFileName());
        bodyPart.setHeader("Content-Disposition", format("form-data; name=\"%s\"; filename=\"%s\"", multipartPart.getFieldName(), multipartPart.getFileName()));

    } else {
        bodyPart.setHeader("Content-Disposition", format("form-data; name=\"%s\"", multipartPart.getFieldName()));
    }

    bodyPart.setDataHandler(new DataHandler(new EncodedDataSource(config, multipartPart.getContentType(), multipartPart.getContent())));
    bodyPart.setHeader("Content-Type", multipartPart.getContentType());

    return bodyPart;
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:18,代码来源:CoreEncoders.java

示例5: createMultiPart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * 创建复杂的正文
 * @return
 * @throws MessagingException 
 */
private Multipart createMultiPart() throws MessagingException {
	// TODO Auto-generated method stub
	Multipart multipart=new MimeMultipart();
	
	//第一块
	BodyPart bodyPart1=new MimeBodyPart();
	bodyPart1.setText("创建复杂的邮件,此为正文部分");
	multipart.addBodyPart(bodyPart1);
	
	//第二块 以附件形式存在
	MimeBodyPart bodyPart2=new MimeBodyPart();
	//设置附件的处理器
	FileDataSource attachFile=new FileDataSource(ClassLoader.getSystemResource("attach.txt").getFile());
	DataHandler dh=new DataHandler(attachFile);
	bodyPart2.setDataHandler(dh);
	bodyPart2.setDisposition(Part.ATTACHMENT);
	bodyPart2.setFileName("test");
	multipart.addBodyPart(bodyPart2);
	
	return multipart;
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:27,代码来源:SimpleSendReceiveMessage.java

示例6: addAlternativePart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Add a multipart/alternative part to message body
 *
 * @param plainContent
 *            the content of the text/plain sub-part
 * @param htmlContent
 *            the content of the text/html sub-part
 * @param charset
 *            the character set for the part
 * @throws PackageException
 */
@PublicAtsApi
public void addAlternativePart(
                                String plainContent,
                                String htmlContent,
                                String charset ) throws PackageException {

    MimeMultipart alternativePart = new MimeMultipart("alternative");

    try {
        // create a new text/plain part
        MimeBodyPart plainPart = new MimeBodyPart();
        plainPart.setText(plainContent, charset, PART_TYPE_TEXT_PLAIN);
        plainPart.setDisposition(MimeBodyPart.INLINE);

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setText(htmlContent, charset, PART_TYPE_TEXT_HTML);
        htmlPart.setDisposition(MimeBodyPart.INLINE);

        alternativePart.addBodyPart(plainPart, 0);
        alternativePart.addBodyPart(htmlPart, 1);

        MimeBodyPart mimePart = new MimeBodyPart();
        mimePart.setContent(alternativePart);

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

示例7: addAttachmentDir

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Appends all files in a specified folder as attachments
 *
 * @param folder the folder containing all files to be attached
 * @throws PackageException
 */
@PublicAtsApi
public void addAttachmentDir(
                              String folder ) throws PackageException {

    // fetch list of files in specified directory
    File dir = new File(folder);
    File[] list = dir.listFiles();
    if (null == list) {
        throw new PackageException("Could not read from directory '" + folder + "'.");
    } else {
        // process all files, skipping directories
        for (int i = 0; i < list.length; i++) {
            if ( (null != list[i]) && (!list[i].isDirectory())) {
                // add attachment to multipart content
                MimeBodyPart attPart = new MimeBodyPart();
                FileDataSource ds = new FileDataSource(list[i].getPath());

                try {
                    attPart.setDataHandler(new DataHandler(ds));
                    attPart.setDisposition(MimeBodyPart.ATTACHMENT);
                    attPart.setFileName(ds.getName());
                } catch (MessagingException me) {
                    throw new PackageException(me);
                }

                addPart(attPart, PART_POSITION_LAST);
            }
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:37,代码来源:MimePackage.java

示例8: addAttachment

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Add an attachment to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * @param attachmentFilename the name of the attachment as it will
 * appear in the mail (the content type will be determined by this)
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addAttachment(String, org.springframework.core.io.InputStreamSource)
 * @see #addAttachment(String, java.io.File)
 */
public void addAttachment(String attachmentFilename, DataSource dataSource) throws MessagingException {
	Assert.notNull(attachmentFilename, "Attachment filename must not be null");
	Assert.notNull(dataSource, "DataSource must not be null");
	try {
		MimeBodyPart mimeBodyPart = new MimeBodyPart();
		mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
		mimeBodyPart.setFileName(MimeUtility.encodeText(attachmentFilename));
		mimeBodyPart.setDataHandler(new DataHandler(dataSource));
		getRootMimeMultipart().addBodyPart(mimeBodyPart);
	}
	catch (UnsupportedEncodingException ex) {
		throw new MessagingException("Failed to encode attachment filename", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:MimeMessageHelper.java

示例9: makeEmail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private MimeMessage makeEmail(TokenData data, _EmailTemplate template, List<_BridgeMessageContent> contents, boolean allowReply) throws MessagingException, IOException {
    MimeMultipart body = new MimeMultipart();
    body.setSubType("alternative");

    for (_BridgeMessageContent content : contents) {
        MimeMultipart contentBody = new MimeMultipart();
        contentBody.setSubType("related");

        Optional<_EmailTemplateContent> contentTemplateOpt = template.getContent(content.getMime());
        if (!contentTemplateOpt.isPresent()) {
            continue;
        }

        _EmailTemplateContent contentTemplate = contentTemplateOpt.get();
        contentBody.addBodyPart(makeBodyPart(data, contentTemplate, content));

        if (contentTemplate.getContent().contains(EmailTemplateToken.SenderAvatar.getToken()) &&
                data.getSenderAvatar() != null && data.getSenderAvatar().isValid()) {
            log.info("Adding avatar for sender");

            MimeBodyPart avatarBp = new MimeBodyPart();
            _MatrixContent avatar = data.getSenderAvatar();
            String filename = avatar.getFilename().orElse("unknown." + avatar.getType().replace("image/", ""));

            avatarBp.setContent(avatar.getData(), avatar.getType());
            avatarBp.setContentID("<" + senderAvatarId + ">");
            avatarBp.setDisposition("inline; filename=" + filename + "; size=" + avatar.getData().length + ";");

            contentBody.addBodyPart(avatarBp);
        }

        MimeBodyPart part = new MimeBodyPart();
        part.setContent(contentBody);

        body.addBodyPart(part);
    }

    return makeEmail(data, template, body, allowReply);
}
 
开发者ID:kamax-io,项目名称:matrix-appservice-email,代码行数:40,代码来源:EmailFormatterOutboud.java

示例10: handleRequest

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Override
public Parameters handleRequest(Parameters parameters, Context context) {

    context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

    try {

        // Create an empty Mime message and start populating it
        Session session = Session.getDefaultInstance(new Properties());
        MimeMessage message = new MimeMessage(session);
        message.setSubject(EMAIL_SUBJECT, "UTF-8");
        message.setFrom(new InternetAddress(System.getenv("EMAIL_FROM")));
        message.setReplyTo(new Address[] { new InternetAddress(System.getenv("EMAIL_FROM")) });
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(System.getenv("EMAIL_RECIPIENT")));

        MimeBodyPart wrap = new MimeBodyPart();
        MimeMultipart cover = new MimeMultipart("alternative");
        MimeBodyPart html = new MimeBodyPart();
        cover.addBodyPart(html);
        wrap.setContent(cover);
        MimeMultipart content = new MimeMultipart("related");
        message.setContent(content);
        content.addBodyPart(wrap);

        // Create an S3 URL reference to the snapshot that will be attached to this email
        URL attachmentURL = createSignedURL(parameters.getS3Bucket(), parameters.getS3Key());

        StringBuilder sb = new StringBuilder();
        String id = UUID.randomUUID().toString();
        sb.append("<img src=\"cid:");
        sb.append(id);
        sb.append("\" alt=\"ATTACHMENT\"/>\n");
        
        // Add the attachment as a part of the message body
        MimeBodyPart attachment = new MimeBodyPart();
        DataSource fds = new URLDataSource(attachmentURL);
        attachment.setDataHandler(new DataHandler(fds));
        
        attachment.setContentID("<" + id + ">");
        attachment.setDisposition(BodyPart.ATTACHMENT);
         
        attachment.setFileName(fds.getName());
        content.addBodyPart(attachment);

        // Pretty print the Rekognition Labels as part of the Emails HTML content
        String prettyPrintLabels = parameters.getRekognitionLabels().toString();
        prettyPrintLabels = prettyPrintLabels.replace("{", "").replace("}", "");
        prettyPrintLabels = prettyPrintLabels.replace(",", "<br>");            
        html.setContent("<html><body><h2>Uploaded Filename : " + parameters.getS3Key().replace("upload/", "") + 
                        "</h2><p><b>Detected Labels/Confidence</b><br><br>" + prettyPrintLabels + "</p>"+sb+"</body></html>", "text/html");

        // Convert the JavaMail message into a raw email request for sending via SES
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        message.writeTo(outputStream);
        RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
        SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);

        // Send the email using the AWS SES Service
        AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.defaultClient();
        client.sendRawEmail(rawEmailRequest);

    } catch (MessagingException | IOException e) {
        // Convert Checked Exceptions to RuntimeExceptions to ensure that
        // they get picked up by the Step Function infrastructure
        throw new AmazonServiceException("Error in ["+context.getFunctionName()+"]", e);
    }

    context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

    return parameters;
}
 
开发者ID:markwest1972,项目名称:smart-security-camera,代码行数:72,代码来源:SesSendNotificationHandler.java

示例11: sendGMail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
     * Fetch a list of Gmail labels attached to the specified account.
     *
     * @return List of Strings labels.
     */
    private List<String> sendGMail() throws Exception {
        List<String> retVal = new ArrayList<>();
        if (debugLogFileWriter != null) {
            debugLogFileWriter.appendnl("sendGMail begin");
            debugLogFileWriter.flush();
        }

        //create the message
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);

        MimeMessage mimeMessage = new MimeMessage(session);

        mimeMessage.setFrom(new InternetAddress("me"));
        mimeMessage.addRecipient(javax.mail.Message.RecipientType.TO,
                new InternetAddress(mEmailTo));
        mimeMessage.setSubject(mSubject);

        MimeBodyPart mimeBodyText = new MimeBodyPart();
        mimeBodyText.setContent(mMessage, "text/html");
        mimeBodyText.setHeader("Content-Type", "text/html; charset=\"UTF-8\"");

        Multipart mp = new MimeMultipart();
        mp.addBodyPart(mimeBodyText);

        if (mAttachments != null && mAttachments.size() > 0) {
            for (String attachment : mAttachments) {
                File attach = new File(attachment);
                if (!attach.exists()) {
                    throw new IOException("File not found");
                }

                MimeBodyPart mimeBodyAttachments = new MimeBodyPart();
                String fileName = attach.getName();
                FileInputStream is = new FileInputStream(attach);
                DataSource source = new ByteArrayDataSource(is, "application/zip");
                mimeBodyAttachments.setDataHandler(new DataHandler(source));
                mimeBodyAttachments.setFileName(fileName);
                mimeBodyAttachments.setHeader("Content-Type", "application/zip" + "; name=\"" + fileName + "\"");
                mimeBodyAttachments.setDisposition(MimeBodyPart.ATTACHMENT);
                mp.addBodyPart(mimeBodyAttachments);
            }
//            mimeBodyAttachments.setHeader("Content-Transfer-Encoding", "base64");
        }

        mimeMessage.setContent(mp);

//        mimeMessage.setText(mMessage);
        //encode in base64url string
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        mimeMessage.writeTo(bytes);
        String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray());

        //create the message
        Message message = new Message();
        message.setRaw(encodedEmail);

        if (debugLogFileWriter != null) {
            debugLogFileWriter.appendnl("sending message using com.google.api.services.gmail.Gmail begin");
            debugLogFileWriter.flush();
        }

        //send the message ("me" => the current selected google account)
        Message result = mGmailService.users().messages().send("me", message).execute();

        if (debugLogFileWriter != null) {
            debugLogFileWriter.appendnl("sending message using com.google.api.services.gmail.Gmail ended with result:\n")
                    .append(result.toPrettyString());
            debugLogFileWriter.flush();
        }

        retVal.add(AndiCar.getAppResources().getString(R.string.gen_mail_sent));
        return retVal;
    }
 
开发者ID:mkeresztes,项目名称:AndiCar,代码行数:80,代码来源:SendGMailTask.java

示例12: sendEmail

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
public void sendEmail(String html, List<Attachment> attachments, InternetAddress recipient, String title)
        throws MessagingException, UnsupportedEncodingException {
    Properties properties = new Properties();
    properties.put("mail.smtp.host", smtpHost);
    properties.put("mail.smtp.port", smtpPort);
    properties.put("mail.smtp.auth", smtpAuth);
    properties.put("mail.smtp.starttls.enable", smtpStarttls);
    properties.put("mail.user", userName);
    properties.put("mail.password", password);

    Authenticator auth = new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, password);
        }
    };

    Session session = Session.getInstance(properties, auth);

    Message msg = new MimeMessage(session);

    msg.setFrom(new InternetAddress(mailFrom, mailFromName));

    InternetAddress[] toAddresses = { recipient };

    msg.setRecipients(Message.RecipientType.TO, toAddresses);
    msg.setSubject(javax.mail.internet.MimeUtility.encodeText(title, "UTF-8", "Q"));
    msg.setSentDate(new Date());

    MimeBodyPart wrap = new MimeBodyPart();

    MimeMultipart cover = new MimeMultipart("alternative");

    MimeBodyPart htmlContent = new MimeBodyPart();
    MimeBodyPart textContent = new MimeBodyPart();
    cover.addBodyPart(textContent);
    cover.addBodyPart(htmlContent);

    wrap.setContent(cover);

    MimeMultipart content = new MimeMultipart("related");
    content.addBodyPart(wrap);

    for (Attachment attachment : attachments) {
        ByteArrayDataSource dSource = new ByteArrayDataSource(Base64.decodeBase64(attachment.getBase64Image()),
                attachment.getMimeType());
        MimeBodyPart filePart = new MimeBodyPart();
        filePart.setDataHandler(new DataHandler(dSource));
        filePart.setFileName(attachment.getFileName());
        filePart.setHeader("Content-ID", "<" + attachment.getCid() + ">");
        filePart.setDisposition(MimeBodyPart.INLINE);
        content.addBodyPart(filePart);
    }

    htmlContent.setContent(html, "text/html; charset=UTF-8");
    textContent.setContent(
            "Twoj klient poczty nie wspiera formatu HTML/Your e-mail client doesn't support HTML format.",
            "text/plain; charset=UTF-8");

    msg.setContent(content);

    Transport.send(msg);
}
 
开发者ID:filipcynarski,项目名称:EMailSenderService,代码行数:63,代码来源:EmailMessage.java

示例13: send

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
	 * Mailテンプレートの内容を送信する。
	 * @param templ メール送信。
	 * @param session メールセッション。
	 * @throws Exception 例外。
	 */
	public void send(final MailTemplate templ, final Session session) throws Exception {
		String subject = templ.getMailSubject();
		log.debug("mail subject=" + subject);
		InternetAddress[] tolist = this.getAddressList(templ.getToList());
		InternetAddress[] cclist = this.getAddressList(templ.getCcList());
		InternetAddress[] bcclist = this.getAddressList(templ.getBccList());
		MimeMessage msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress(templ.getFrom(), templ.getFromPersonal(), "UTF-8"));
		InternetAddress[] replyTo = new InternetAddress[1];
		replyTo[0] = new InternetAddress(templ.getReplyTo());
		msg.setReplyTo(replyTo);
		msg.setRecipients(Message.RecipientType.TO, tolist);
		if (cclist != null) {
			msg.setRecipients(Message.RecipientType.CC, cclist);
		}
		if (bcclist != null) {
			msg.setRecipients(Message.RecipientType.BCC, bcclist);
		}
//		msg.setSubject(subject, "ISO-2022-JP");
		msg.setSubject(subject, "UTF-8");

		// mixed
		Multipart mixedPart = new MimeMultipart("mixed");

		// alternative
		MimeBodyPart alternativeBodyPart = new MimeBodyPart();
		MimeMultipart alternativePart = new MimeMultipart("alternative");
		alternativeBodyPart.setContent(alternativePart);
		mixedPart.addBodyPart(alternativeBodyPart);

		// text mail
		MimeBodyPart textBodyPart = new MimeBodyPart();
//		textBodyPart.setText(templ.getMailTextBody(), "ISO-2022-JP", "plain");
		textBodyPart.setText(templ.getMailTextBody(), "UTF-8", "plain");
		textBodyPart.setHeader("Content-Transfer-Encoding", "base64");
		alternativePart.addBodyPart(textBodyPart);	// alter

		// related
		MimeBodyPart relatedBodyPart = new MimeBodyPart();
		Multipart relatedPart = new MimeMultipart("related");
		relatedBodyPart.setContent(relatedPart);
		alternativePart.addBodyPart(relatedBodyPart);

		// html mail
		MimeBodyPart htmlBodyPart = new MimeBodyPart();
//		htmlBodyPart.setText(templ.getMailHtmlBody(), "ISO-2022-JP", "html");
		htmlBodyPart.setText(templ.getMailHtmlBody(), "UTF-8", "html");
		htmlBodyPart.setHeader("Content-Transfer-Encoding", "base64");
		relatedPart.addBodyPart(htmlBodyPart);

		// attach file
		for (MailTemplate.AttachFileInfo finfo: templ.getAttachFileList()) {
			MimeBodyPart attachBodyPart = new MimeBodyPart();
			DataSource dataSource2 = new FileDataSource(finfo.getPath());
			DataHandler dataHandler2 = new DataHandler(dataSource2);
			attachBodyPart.setDataHandler(dataHandler2);
//			attachBodyPart.setFileName(MimeUtility.encodeWord(finfo.getFilename(), "iso-2022-jp", "B"));
//			attachBodyPart.setFileName(MimeUtility.encodeWord(finfo.getFilename(), "UTF-8", null));
			attachBodyPart.setFileName(MimeUtility.encodeWord(finfo.getFilename(), "UTF-8", "B"));
			attachBodyPart.setDisposition("attachment");  // attachment 指定しておく
			mixedPart.addBodyPart(attachBodyPart);
		}
		msg.setContent(mixedPart);
		Transport.send(msg);
	}
 
开发者ID:takayanagi2087,项目名称:dataforms,代码行数:72,代码来源:MailSender.java

示例14: addInline

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
/**
 * Add an inline element to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param contentId the content ID to use. Will end up as "Content-ID" header
 * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
 * Can be referenced in HTML source via src="cid:myId" expressions.
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addInline(String, java.io.File)
 * @see #addInline(String, org.springframework.core.io.Resource)
 */
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
	Assert.notNull(contentId, "Content ID must not be null");
	Assert.notNull(dataSource, "DataSource must not be null");
	MimeBodyPart mimeBodyPart = new MimeBodyPart();
	mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
	// We're using setHeader here to remain compatible with JavaMail 1.2,
	// rather than JavaMail 1.3's setContentID.
	mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
	mimeBodyPart.setDataHandler(new DataHandler(dataSource));
	getMimeMultipart().addBodyPart(mimeBodyPart);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:MimeMessageHelper.java


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