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


Java MimeMessage.setContent方法代码示例

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


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

示例1: createMimeMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 * 创建一封只包含文本的简单邮件
 *
 * @param session
 *            和服务器交互的会话
 * @param sendMail
 *            发件人邮箱
 * @param receiveMail
 *            收件人邮箱
 * @return
 * @throws Exception
 */
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String username,String pwd)
		throws Exception {
	// 1. 创建一封邮件
	MimeMessage message = new MimeMessage(session);

	// 2. From: 发件人(昵称有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改昵称)
	message.setFrom(new InternetAddress(sendMail, "Mircle", "UTF-8"));

	// 3. To: 收件人(可以增加多个收件人、抄送、密送)
	message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "", "UTF-8"));

	// 4. Subject: 邮件主题(标题有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改标题)
	message.setSubject(subject, "UTF-8");

	// 5. Content: 邮件正文(可以使用html标签)(内容有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改发送内容)
	message.setContent(getContent(username,pwd), "text/html;charset=UTF-8");

	// 6. 设置发件时间
	message.setSentDate(new Date());

	// 7. 保存设置
	message.saveChanges();

	return message;
}
 
开发者ID:miracle857,项目名称:weibo,代码行数:38,代码来源:Mail.java

示例2: process

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public String process() {
	logger.info("Running inside MailBatchlet batchlet ");
	String fromAddress = stepContext.getProperties().getProperty("mail.from");
	String toAddress = stepContext.getProperties().getProperty("mail.to");

	try {
		MimeMessage m = new MimeMessage(mailSession);
		Address from = new InternetAddress(fromAddress);
		Address[] to = new InternetAddress[] { new InternetAddress(toAddress) };

		m.setFrom(from);
		m.setRecipients(TO, to);
		m.setSubject("Batch on wildfly executed");
		m.setSentDate(new java.util.Date());
		m.setContent("Job Execution id " + jobContext.getExecutionId() + " warned disk space getting low!",
				"text/plain");
		send(m);

	} catch (javax.mail.MessagingException e) {
		logger.log(SEVERE, "error send mail", e);

	}
	return COMPLETED.name();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:26,代码来源:MailBatchlet.java

示例3: createMimeMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 *
 * @param session 和服务器交互的会话
 * @param mail 邮件内容
 * @return
 * @throws Exception
 */
private static MimeMessage createMimeMessage(Session session, String SendAccount, Mail mail) throws Exception {
    MimeMessage message = new MimeMessage(session);
    //From: 发件人
    message.setFrom(new InternetAddress(SendAccount, mail.getPersonal(), "UTF-8"));
    // To: 收件人
    message.setRecipients(MimeMessage.RecipientType.TO, mail.getAddresses());
    // Subject: 邮件主题
    message.setSubject(mail.getSubject(), "UTF-8");
    // Content: 邮件正文(可以使用html标签)
    message.setContent(mail.getContext(), "text/html;charset=UTF-8");
    // 设置发件时间
    message.setSentDate(new Date());
    message.saveChanges();
    return message;
}
 
开发者ID:BetaSummer,项目名称:sztw,代码行数:23,代码来源:MailCore.java

示例4: sendAccountActivateEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void sendAccountActivateEmail(String email, String uuid, int userId) {
  Session session;
  try {
    session = getSession();
    MimeMessage message = new MimeMessage(session);
    message.setSubject("������֤��");
    message.setSentDate(new Date());
    message.setFrom(new InternetAddress(FROM));
    message.setRecipient(RecipientType.TO, new InternetAddress(email));
    message.setContent("�����û�"+userId+":������֤��Ϊ��"+uuid,
        "text/html;charset=utf-8");
    message.saveChanges();
    Transport.send(message);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:18,代码来源:EmailUtils.java

示例5: sendMailBatch

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void sendMailBatch(List<String> to, String title, String content) throws MessagingException {
    Session session = Session.getDefaultInstance(properties, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(fromAddress));
    to.forEach(address -> {
        try {
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(address));
        } catch (MessagingException ignored) {
        }
    });
    message.setSubject(title);
    message.setContent(content, "text/html;charset=UTF-8");
    Transport.send(message);
}
 
开发者ID:superkoh,项目名称:k-framework,代码行数:20,代码来源:JavaMailMessage.java

示例6: send

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public boolean send() throws Exception {
    Properties props = _setProperties();
    Session session = Session.getInstance(props, this);
    MimeMessage msg = new MimeMessage(session);
    msg.setSubject(subject);
    msg.setFrom(new InternetAddress("[email protected]"));
    msg.setRecipients(MimeMessage.RecipientType.TO, new InternetAddress[] {
            new InternetAddress("[email protected]")
    });
    msg.setSentDate(new Date());
    msg.setContent(multipart);
    Transport.send(msg);
    return true;
}
 
开发者ID:KursX,项目名称:Parallator,代码行数:15,代码来源:MailSender.java

示例7: createEmailWithAttachment

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static MimeMessage createEmailWithAttachment(String to, String from, String subject,
                                      String bodyText,String filePath) throws MessagingException{
    File file = new File(filePath);
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    MimeMessage email = new MimeMessage(session);
    Multipart multipart = new MimeMultipart();
    InternetAddress tAddress = new InternetAddress(to);
    InternetAddress fAddress = new InternetAddress(from);
    email.setFrom(fAddress);
    email.addRecipient(javax.mail.Message.RecipientType.TO, tAddress);
    email.setSubject(subject);
    if (file.exists()) {
        source = new FileDataSource(filePath);
        messageFilePart = new MimeBodyPart();
        messageBodyPart = new MimeBodyPart();
        try {
            messageBodyPart.setText(bodyText);
            messageFilePart.setDataHandler(new DataHandler(source));
            messageFilePart.setFileName(file.getName());

            multipart.addBodyPart(messageBodyPart);
            multipart.addBodyPart(messageFilePart);
            email.setContent(multipart);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }else
        email.setText(bodyText);
    return email;
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:32,代码来源:EmailShield.java

示例8: sendEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void sendEmail(EmailSettingContent emailSetting, String acceptor, String subject, String body) {
    Properties props = buildProperty(emailSetting);

    Session session = Session.getInstance(props, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            String username = null;
            String password = null;
            if (emailSetting.isAuthenticated()) {
                username = emailSetting.getUsername();
                password = emailSetting.getPassword();
            }
            return new PasswordAuthentication(username, password);
        }
    });
    try {

        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(emailSetting.getSender()));
        message.setRecipients(Message.RecipientType.TO,
            InternetAddress.parse(acceptor));

        message.setSubject(subject, "utf8");
        message.setContent(body, "text/html;charset=utf8");
        Transport.send(message);

    } catch (Throwable throwable) {
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:30,代码来源:SmtpUtil.java

示例9: createMimeMultiparts

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 * Determine the MimeMultipart objects to use, which will be used
 * to store attachments on the one hand and text(s) and inline elements
 * on the other hand.
 * <p>Texts and inline elements can either be stored in the root element
 * itself (MULTIPART_MODE_MIXED, MULTIPART_MODE_RELATED) or in a nested element
 * rather than the root element directly (MULTIPART_MODE_MIXED_RELATED).
 * <p>By default, the root MimeMultipart element will be of type "mixed"
 * (MULTIPART_MODE_MIXED) or "related" (MULTIPART_MODE_RELATED).
 * The main multipart element will either be added as nested element of
 * type "related" (MULTIPART_MODE_MIXED_RELATED) or be identical to the root
 * element itself (MULTIPART_MODE_MIXED, MULTIPART_MODE_RELATED).
 * @param mimeMessage the MimeMessage object to add the root MimeMultipart
 * object to
 * @param multipartMode the multipart mode, as passed into the constructor
 * (MIXED, RELATED, MIXED_RELATED, or NO)
 * @throws MessagingException if multipart creation failed
 * @see #setMimeMultiparts
 * @see #MULTIPART_MODE_NO
 * @see #MULTIPART_MODE_MIXED
 * @see #MULTIPART_MODE_RELATED
 * @see #MULTIPART_MODE_MIXED_RELATED
 */
protected void createMimeMultiparts(MimeMessage mimeMessage, int multipartMode) throws MessagingException {
	switch (multipartMode) {
		case MULTIPART_MODE_NO:
			setMimeMultiparts(null, null);
			break;
		case MULTIPART_MODE_MIXED:
			MimeMultipart mixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
			mimeMessage.setContent(mixedMultipart);
			setMimeMultiparts(mixedMultipart, mixedMultipart);
			break;
		case MULTIPART_MODE_RELATED:
			MimeMultipart relatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
			mimeMessage.setContent(relatedMultipart);
			setMimeMultiparts(relatedMultipart, relatedMultipart);
			break;
		case MULTIPART_MODE_MIXED_RELATED:
			MimeMultipart rootMixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
			mimeMessage.setContent(rootMixedMultipart);
			MimeMultipart nestedRelatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
			MimeBodyPart relatedBodyPart = new MimeBodyPart();
			relatedBodyPart.setContent(nestedRelatedMultipart);
			rootMixedMultipart.addBodyPart(relatedBodyPart);
			setMimeMultiparts(rootMixedMultipart, nestedRelatedMultipart);
			break;
		default:
			throw new IllegalArgumentException("Only multipart modes MIXED_RELATED, RELATED and NO supported");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:52,代码来源:MimeMessageHelper.java

示例10: sendMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void sendMail(String to, String title, String content) throws MessagingException {
    Session session = Session.getDefaultInstance(properties, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(fromAddress));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(title);
    message.setContent(content, "text/html;charset=UTF-8");
    Transport.send(message);
}
 
开发者ID:superkoh,项目名称:k-framework,代码行数:15,代码来源:JavaMailMessage.java

示例11: enviarMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void enviarMail(Persona cliente, String asunto, String mensaje) {
	if (cliente.getPersonaMail() != null) {
		Mail mail = obtenerMailEmisor();
		Properties props = conectarse(mail);
		Session session = autentificar(mail, props);

		try {
			BodyPart texto = new MimeBodyPart();

			// Texto del mensaje
			texto.setText(mensaje);

			MimeMultipart multiParte = new MimeMultipart();
			multiParte.addBodyPart(texto);

			MimeMessage message = new MimeMessage(session);

			// Se rellena el From
			InternetAddress emisor = new InternetAddress(mail.getNombre() + " <" + mail.getMail() + ">");
			message.setFrom(emisor);

			// Se rellenan los destinatarios
			InternetAddress receptor = new InternetAddress();
			receptor.setAddress(cliente.getPersonaMail());
			message.addRecipient(Message.RecipientType.TO, receptor);

			// Se rellena el subject
			message.setSubject(asunto);

			// Se mete el texto y la foto adjunta.
			message.setContent(multiParte);

			Transport.send(message);

		} catch (MessagingException e) {
			messageService.informUser("Poliza creada, falló envío de mail");
		}

	}
}
 
开发者ID:leandrogonqn,项目名称:Proyecto2017Seguros,代码行数:41,代码来源:Mail.java

示例12: enviarMailPoliza

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void enviarMailPoliza(Persona cliente) {
	if (cliente.getPersonaMail() != null) {
		Mail mail = obtenerMailEmisor();
		Properties props = conectarse(mail);
		Session session = autentificar(mail, props);

		String asunto = "Emisión de Póliza";

		String mensaje = "Buenos días " + cliente.toString()
				+ ", \r\nSu poliza ya esta emitida, en los proximos días se la estaremos acercando a su domicilio.\r\nSaludos cordiales.\r\n"
				+ "Pacinetes S.R.L.";

		try {
			BodyPart texto = new MimeBodyPart();

			// Texto del mensaje
			texto.setText(mensaje);

			MimeMultipart multiParte = new MimeMultipart();
			multiParte.addBodyPart(texto);

			MimeMessage message = new MimeMessage(session);

			// Se rellena el From
			InternetAddress emisor = new InternetAddress(mail.getNombre() + " <" + mail.getMail() + ">");
			message.setFrom(emisor);

			// Se rellenan los destinatarios
			InternetAddress receptor = new InternetAddress();
			receptor.setAddress(cliente.getPersonaMail());
			message.addRecipient(Message.RecipientType.TO, receptor);

			// Se rellena el subject
			message.setSubject(asunto);

			// Se mete el texto y la foto adjunta.
			message.setContent(multiParte);

			Transport.send(message);

		} catch (MessagingException e) {
			messageService.informUser("Poliza creada, falló envío de mail");
		}
	}
}
 
开发者ID:leandrogonqn,项目名称:Proyecto2017Seguros,代码行数:46,代码来源:Mail.java

示例13: createImageMail

import javax.mail.internet.MimeMessage; //导入方法依赖的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

示例14: setMimeMessageContent

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
protected void setMimeMessageContent(MimeMessage mimeMessage, MailInfo mailInfo) 
    throws MessagingException {
    if (mailInfo.getContentType() == null) {
        mimeMessage.setText(mailInfo.getMessage());
    } else {
        mimeMessage.setContent(mailInfo.getMessage(), mailInfo.getContentType());
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:9,代码来源:SendMailJob.java

示例15: sendEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void sendEmail(String message, String sendTo, String group_topic) {
  Properties properties = System.getProperties();

  if (config.getSmtpAuth()) {
    properties.setProperty("mail.user", config.getSmtpUser());
    properties.setProperty("mail.password", config.getSmtpPasswd());
  }
  properties.setProperty("mail.smtp.host", config.getSmtpServer());

  Session session = Session.getDefaultInstance(properties);

  MimeMessage mimeMessage = new MimeMessage(session);

  try {
    String[] sendToArr = sendTo.split(";");
    mimeMessage.setFrom(new InternetAddress(config.getMailSender()));
    if (sendToArr.length > 1) {
      String cc = "";
      for (int i = 1; i < sendToArr.length; i++) {
        cc += i == sendToArr.length - 1 ? sendToArr[i] : sendToArr[i] + ",";
      }
      mimeMessage.addRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
    }
    mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(sendToArr[0]));

    String[] group_topicArr = group_topic.split("_");
    String subject = config.getMailSubject();
    if (subject.contains("{group}")) {
      subject = subject.replace("{group}", group_topicArr[0]);
    }
    if (subject.contains("{topic}")) {
      subject = subject.replace("{topic}", group_topicArr[1]);
    }
    mimeMessage.setSubject(subject);
    mimeMessage.setSentDate(new Date());
    mimeMessage.setContent(message, "text/html");

    Transport.send(mimeMessage);
  } catch (

  Exception e) {
    LOG.error("sendEmail faild!", e);
  }
}
 
开发者ID:chickling,项目名称:kmanager,代码行数:45,代码来源:EmailSender.java


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