當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。