本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
示例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;
}
示例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);
}