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


Java MimeBodyPart.setContentID方法代碼示例

本文整理匯總了Java中javax.mail.internet.MimeBodyPart.setContentID方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeBodyPart.setContentID方法的具體用法?Java MimeBodyPart.setContentID怎麽用?Java MimeBodyPart.setContentID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.internet.MimeBodyPart的用法示例。


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

示例1: readHeaders

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
private MimeBodyPart readHeaders() throws IOException, MessagingException {
	if (pis.isStreamEnd()) {
		return null;
	}
	
	byte[] sep = new byte[2];
	int read = pis.read(sep);
	
	if (read != 2 || !Arrays.equals(sep, sLine))
	{
		return null;
	}
	
	MimeBodyPart bodyPart = new MimeBodyPart();		
	PartInputStream lis = new PartInputStream(pis, sLine);
	
	for (String line = IOUtils.toString(lis, "ascii"); !line.isEmpty(); line = IOUtils.toString(lis, "ascii")) {
		Matcher mHeader = pHeader.matcher(line);
		
		if (mHeader.matches()) {
			bodyPart.addHeader(mHeader.group(1), mHeader.group(2));
			
			if (mHeader.group(1).equalsIgnoreCase("Content-ID")) {
				bodyPart.setContentID(mHeader.group(2));
			}
		}
		
		lis.nextPart();
	}
	
	return bodyPart;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:33,代碼來源:BigMimeMultipart.java

示例2: addMtomPart

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
private void addMtomPart(MimeMultipart mp, RequestableHttpVariable variable, Object httpVariableValue) throws IOException, MessagingException {
	String stringValue = ParameterUtils.toString(httpVariableValue);
	String filepath = Engine.theApp.filePropertyManager.getFilepathFromProperty(stringValue, getProject().getName());
	String cid = variable.getMtomCid(stringValue);
	
	Engine.logBeans.debug("(HttpConnector) Prepare the MTOM attachment with cid: " + cid + ". Converting the path '" + stringValue + "' to '" + filepath + "'");
	
	MimeBodyPart bp = new MimeBodyPart();
	bp.attachFile(filepath);
	bp.setContentID(cid);
	mp.addBodyPart(bp);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:13,代碼來源:HttpConnector.java

示例3: createImageMail

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
/**
  * @Method: createImageMail
  * @Description: ����һ���ʼ����Ĵ�ͼƬ���ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createImageMail(String subject, String content, String imagePath) throws Exception {

      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content, "text/html;charset=UTF-8");
      MimeBodyPart image = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(imagePath));
      image.setDataHandler(dh);
      image.setContentID("xxx.jpg");
      MimeMultipart mm = new MimeMultipart();
      mm.addBodyPart(text);
      mm.addBodyPart(image);
      mm.setSubType("related");

      message.setContent(mm);
      message.saveChanges();
      return message;
  }
 
開發者ID:AlanYangs,項目名稱:Log4Reports,代碼行數:39,代碼來源:EmailUtil.java

示例4: createMixedMail

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
/**
  * @Method: createMixedMail
  * @Description: ����һ��������ʹ�ͼƬ���ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createMixedMail(String subject, String content, String imagePath, String filePath) throws Exception {
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content,"text/html;charset=UTF-8");
      
      MimeBodyPart image = new MimeBodyPart();
      image.setDataHandler(new DataHandler(new FileDataSource(imagePath)));
      image.setContentID("aaa.jpg");
      
      MimeBodyPart attach = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(filePath));
      attach.setDataHandler(dh);
      attach.setFileName(dh.getName());

      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(text);
      mp.addBodyPart(image);
      mp.setSubType("related");
      
      MimeBodyPart bodyContent = new MimeBodyPart();
      bodyContent.setContent(mp);
      message.saveChanges();
      return message;
  }
 
開發者ID:AlanYangs,項目名稱:Log4Reports,代碼行數:46,代碼來源:EmailUtil.java

示例5: sendTextEmail

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
public static void sendTextEmail(String recvEmail) {
	try { 
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", "smtp.qq.com");
		props.setProperty("mail.smtp.auth", "true");
		props.put("mail.smtp.ssl.enable", "true");
		props.put("mail.smtp.socketFactory.port",  "994");
		Session session = Session.getInstance(props, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication("463112653", "manllfvunnfwbjhh");
			}
		});
		session.setDebug(true);
		Message msg = new MimeMessage(session);
		msg.setSubject("Hello Vme");
		//整個郵件的MultiPart(不能直接加入內容,需要在bodyPart中加入)
		Multipart emailPart = new MimeMultipart();
		MimeBodyPart attr1 = new MimeBodyPart();
		attr1.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/2601169057.png")));
		attr1.setFileName("tip.pic");
		
		MimeBodyPart attr2 = new MimeBodyPart();
		attr2.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
		attr2.setFileName(MimeUtility.encodeText("哦圖像"));
		
		MimeBodyPart content = new MimeBodyPart();
		MimeMultipart contentPart = new MimeMultipart();
		
		MimeBodyPart imgPart = new MimeBodyPart();
		imgPart.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
		imgPart.setContentID("pic");
		
		MimeBodyPart htmlPart = new MimeBodyPart();
		htmlPart.setContent("<h1><a href='www.baidu.com'>百度一下</a><img src='cid:pic'/></h1>", "text/html;charset=utf-8");
		
		contentPart.addBodyPart(imgPart);
		contentPart.addBodyPart(htmlPart);
		content.setContent(contentPart);
		
		emailPart.addBodyPart(attr1);
		emailPart.addBodyPart(attr2);
		emailPart.addBodyPart(content);
		msg.setContent(emailPart);
		
		msg.setFrom(new InternetAddress("[email protected]"));
		msg.setRecipients(RecipientType.TO, InternetAddress.parse("[email protected],[email protected]"));
		msg.setRecipients(RecipientType.CC, InternetAddress.parse("[email protected],[email protected]"));
		Transport.send(msg);
	} catch (Exception e) {
		e.printStackTrace();
	} 
}
 
開發者ID:Fetax,項目名稱:Fetax-AI,代碼行數:55,代碼來源:EmailHelper.java

示例6: 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

示例7: 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

示例8: sendEmail

import javax.mail.internet.MimeBodyPart; //導入方法依賴的package包/類
/**
 * 用來發送郵件
 *
 * @param session 與發送郵件的主機的連接(會話)
 * @param email   寫好的郵件
 * @throws Exception 出現異常
 */
public static void sendEmail(Session session, Email email) throws Exception {
    // 獲取發送郵件的信息類
    MimeMessage message = new MimeMessage(session);

    // 設置發送方郵件地址
    message.setFrom(new InternetAddress(email.getFrom()));
    // 設置發送類型和被發送方的郵件地址
    if (!email.getTo().isEmpty()) {
        message.setRecipients(RecipientType.TO, email.getTo());
    }
    if (!email.getCc().isEmpty()) {
        message.setRecipients(RecipientType.CC, email.getCc());
    }
    if (!email.getBcc().isEmpty()) {
        message.setRecipients(RecipientType.BCC, email.getBcc());
    }
    // 設置郵件主題
    message.setSubject(email.getSubject(), "utf-8");
    // 設置郵件內容
    MimeMultipart content = new MimeMultipart();
    // 郵件正文
    MimeBodyPart text = new MimeBodyPart();
    text.setContent(email.getContent(), email.getType());
    content.addBodyPart(text);
    // 設置附件
    if (email.getAttachments() != null) {
        for (AttachmentBean attachment : email.getAttachments()) {
            MimeBodyPart part = new MimeBodyPart();
            part.attachFile(attachment.getFile());
            part.setFileName(MimeUtility.encodeText(attachment
                    .getFileName()));
            if (attachment.getCid() != null) {
                part.setContentID(attachment.getCid());
            }
            content.addBodyPart(part);
        }
    }
    // 將郵件內容添加到信息中
    message.setContent(content);
    // 發送郵件
    Transport.send(message);
}
 
開發者ID:FlyingHe,項目名稱:UtilsMaven,代碼行數:50,代碼來源:MailUtils.java


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