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


Java MimeMessage.setSubject方法代碼示例

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


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

示例1: createSimpleMail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
  * @Method: createSimpleMail
  * @Description: ����һ��ֻ�����ı����ݵ��ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createSimpleMail(String subject, String content) 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);
      //�ʼ����ı�����
      message.setContent(content, "text/html;charset=UTF-8");
      //���ش����õ��ʼ�����
      return message;
  }
 
開發者ID:AlanYangs,項目名稱:Log4Reports,代碼行數:32,代碼來源:EmailUtil.java

示例2: sendEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private static void sendEmail(String fromEmail, String toEmail, String subject, String body, boolean html)
throws MessagingException{
	MimeMessage message = new MimeMessage(MAILING_SESSION);
	message.setFrom(new InternetAddress(fromEmail));
	InternetAddress[] addresses = InternetAddress.parse(toEmail);//one or more addresses
	message.addRecipients(RecipientType.TO, addresses);
	message.setReplyTo(addresses);
	message.setSubject(subject);
	String subType;
	if(html){
		subType = "html";
	}else{
		subType = "plain";
	}
	message.setText(body, "UTF-8", subType);
	Transport.send(message);
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:18,代碼來源:DatarouterEmailTool.java

示例3: sendEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private Boolean sendEmail(String randomKey, UserEntity userEntity) {
	try {
		MimeMessage message = new MimeMessage(mailSession);
		message.setFrom(new InternetAddress(Config.getEmailFrom()));
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(userEntity.getEmail()));
		message.setSubject("Recovery Password Email");
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("Dear user,\n\n");
		stringBuilder.append("Someone requested to recover forgotten password in our soapbox race world server.\n\n");
		stringBuilder.append("If wasn't you, just ignore this email.\n\n");
		stringBuilder.append("You can click this link to reset your password:\n\n");
		stringBuilder.append(Config.getServerAddress());
		stringBuilder.append("/soapbox-race-core/password.jsp?randomKey=");
		stringBuilder.append(randomKey);
		stringBuilder.append("\n\nThanks for playing!\n\n");
		stringBuilder.append("\n\nSBRW Team.\n");
		message.setText(stringBuilder.toString());
		Transport.send(message);
		return true;
	} catch (MessagingException mex) {
		mex.printStackTrace();
		return false;
	}
}
 
開發者ID:SoapboxRaceWorld,項目名稱:soapbox-race-core,代碼行數:25,代碼來源:RecoveryPasswordBO.java

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

示例5: sendHtmlEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void sendHtmlEmail(EmailObject email) throws Exception {
    // 創建Session實例對象
    Session session = Session.getInstance(props, new EmailAuthenticator());

    // 創建MimeMessage實例對象
    MimeMessage message = new MimeMessage(session);
    // 設置郵件主題
    message.setSubject(email.getEmailSubject(),"utf-8");
    // 設置發送人
    message.setFrom(new InternetAddress(from));
    // 設置發送時間
    message.setSentDate(new Date());
    // 設置收件人
    message.setRecipients(MimeMessage.RecipientType.TO, InternetAddress.parse(email.getToEmail()));
    // 設置html內容為郵件正文,指定MIME類型為text/html類型,並指定字符編碼為gbk
    message.setContent(email.getEmailContent(), "text/html;charset=utf-8");
    // 保存並生成最終的郵件內容
    message.saveChanges();
    // 發送郵件
    Transport.send(message);
    //記錄郵件發送日誌
    SendEmailLog sendEmailLog = new SendEmailLog();
    sendEmailLog.setToemail(email.getToEmail());
    sendEmailLog.setSubject(email.getEmailSubject());
    sendEmailLog.setSenddate(new Date());
    sendEmailLog.setContent(email.getEmailContent());
    sendEmailLogDao.insert(sendEmailLog);
}
 
開發者ID:NeilRen,項目名稱:NEILREN4J,代碼行數:29,代碼來源:EmailUtils.java

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

示例7: makeEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private MimeMessage makeEmail(TokenData data, _EmailTemplate template, MimeMultipart body, boolean allowReply) throws MessagingException, UnsupportedEncodingException {
    MimeMessage msg = new MimeMessage(session);
    if (allowReply) {
        msg.setReplyTo(InternetAddress.parse(recvCfg.getEmail().replace("%KEY%", data.getKey())));
    }

    String sender = data.isSelf() ? sendCfg.getName() : data.getSenderName();
    msg.setFrom(new InternetAddress(sendCfg.getEmail(), sender, StandardCharsets.UTF_8.name()));
    msg.setSubject(processToken(data, template.getSubject()));
    msg.setContent(body);
    return msg;
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:13,代碼來源:EmailFormatterOutboud.java

示例8: createAttachMail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
  * @Method: createAttachMail
  * @Description: ����һ����������ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createAttachMail(String subject, String content, 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 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(attach);
      mp.setSubType("mixed");
      
      message.setContent(mp);
      message.saveChanges();
      return message;
  }
 
開發者ID:AlanYangs,項目名稱:Log4Reports,代碼行數:41,代碼來源:EmailUtil.java

示例9: sendAlertEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void sendAlertEmail(String alert) throws MessagingException{
	String host = "smtp.gmail.com";
	String from = "[email protected]";
	String pass = "3inst3in?";
	Properties props = System.getProperties();
	props.put("mail.smtp.starttls.enable", "true"); // added this line
	props.put("mail.smtp.host", host);
	props.put("mail.smtp.user", from);
	props.put("mail.smtp.password", pass);
	props.put("mail.smtp.port", "587");
	props.put("mail.smtp.auth", "true");

	Session session = Session.getDefaultInstance(props, null);
	MimeMessage message = new MimeMessage(session);
	message.setFrom(new InternetAddress(from));

	InternetAddress[] toAddress = new InternetAddress[alert_recipients.length];

	// To get the array of addresses
	for( int i=0; i < alert_recipients.length; i++ ) { // changed from a while loop
		toAddress[i] = new InternetAddress(alert_recipients[i]);
	}
	//System.out.println(Message.RecipientType.TO);

	for( int i=0; i < toAddress.length; i++) { // changed from a while loop
		message.addRecipient(Message.RecipientType.TO, toAddress[i]);
	}
	message.setSubject("WARNING Something went wrong in the Einstein tunnel");
	message.setText(alert);
	Transport transport = session.getTransport("smtp");
	transport.connect(host, from, pass);
	transport.sendMessage(message, message.getAllRecipients());
	transport.close();

}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:36,代碼來源:Resetter.java

示例10: createEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private static MimeMessage createEmail(String to, String from, String subject, String bodyText) throws MessagingException {
	Properties props = new Properties();
	Session session = Session.getDefaultInstance(props, null);
	MimeMessage email = new MimeMessage(session);
	email.setFrom(new InternetAddress(from));
	email.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
	email.setSubject(subject);
	email.setText(bodyText);
	return email;
}
 
開發者ID:tburne,項目名稱:blog-examples,代碼行數:11,代碼來源:ClientRequestAPI.java

示例11: createMimeMessage

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private MimeMessage createMimeMessage(String from, String subject, String body, Date date) throws AddressException, MessagingException {
    MimeMessage msg = new MimeMessage(greenMail.getSmtp().createSession());
    msg.setFrom(new InternetAddress(from));
    msg.addRecipient(Message.RecipientType.TO,
            new InternetAddress(TEST_RECIP));
    msg.setSubject(subject);
    msg.setText(body);
    msg.setSentDate(date != null ? date : new Date());
    return msg;
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:11,代碼來源:TestMailUtil.java

示例12: buildMail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private MimeMessage buildMail(MimeMessage message) {
	MimeMessage ret = message;
	try {
		Address[] replies = {new InternetAddress(sSender)};
		String[] recipients = sRecipients.split(",|;");
		// Adding sender
		ret.setFrom(new InternetAddress(sSender));
		ret.setSender(new InternetAddress(sSender));
		ret.setReplyTo(replies);
		
		//Adding recipients
		if (recipients[0].indexOf(":") != -1) {
			ret.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[0].split(":")[1]));
		} else {
			ret.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[0]));
		}
		for (int i = 1; i < recipients.length; i++) {
			if (recipients[i].indexOf(":") != -1) {
				String sRecipientType  = recipients[i].split(":")[0];
				String sRecipientAddress  = recipients[i].split(":")[1];
				if ("TO".equalsIgnoreCase(sRecipientType)) {
					ret.addRecipient(Message.RecipientType.TO, new InternetAddress(sRecipientAddress));
				} else if ("BCC".equalsIgnoreCase(sRecipientType)) {
					ret.addRecipient(Message.RecipientType.BCC, new InternetAddress(sRecipientAddress));
				} else {
					ret.addRecipient(Message.RecipientType.CC, new InternetAddress(sRecipientAddress));
				}
			} else {
				ret.addRecipient(Message.RecipientType.CC, new InternetAddress(recipients[i]));
			}
		}

		//Add receipts
		if (getDeliveryReceipt()) {
			message.setHeader("Return-Receipt-To", new InternetAddress(sSender).toString());
		}
		if (getReadReceipt()) {
			message.setHeader("Disposition-Notification-To", new InternetAddress(sSender).toString());
		}
		
		
		//Adding mail subject
		ret.setSubject(sSubject);

		//Adding content
		if (bodyParts.size() > 0) {
			Multipart multipart = new MimeMultipart();
			
			MimeBodyPart msgPart = new MimeBodyPart();
			msgPart.setContent(sMessageText, sContentType);
			multipart.addBodyPart(msgPart);
			
			for (BodyPart bodyPart : bodyParts) {
				multipart.addBodyPart(bodyPart);
			}
			
			ret.setContent(multipart);
		} else {
			ret.setContent(sMessageText, sContentType);
		}
	} catch (Exception e1) {
		Engine.logBeans.error("(SmtpStep) An error occured while trying to build e-mail : " + e1.getStackTrace().toString(), e1);
	}
	return ret;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:66,代碼來源:SmtpStep.java

示例13: sendMailSync

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static void sendMailSync(long userId, Event event, Position position) throws MessagingException {
    User user = Context.getPermissionsManager().getUser(userId);

    Properties properties = null;
    if (!Context.getConfig().getBoolean("mail.smtp.ignoreUserConfig")) {
        properties = getProperties(new PropertiesProvider(user));
    }
    if (properties == null || !properties.containsKey("mail.smtp.host")) {
        properties = getProperties(new PropertiesProvider(Context.getConfig()));
    }
    if (!properties.containsKey("mail.smtp.host")) {
        Log.warning("No SMTP configuration found");
        return;
    }

    Session session = Session.getInstance(properties);

    MimeMessage message = new MimeMessage(session);

    String from = properties.getProperty("mail.smtp.from");
    if (from != null) {
        message.setFrom(new InternetAddress(from));
    }

    message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
    MailMessage mailMessage = NotificationFormatter.formatMailMessage(userId, event, position);
    message.setSubject(mailMessage.getSubject());
    message.setSentDate(new Date());
    message.setContent(mailMessage.getBody(), "text/html; charset=utf-8");

    Transport transport = session.getTransport();
    try {
        Context.getStatisticsManager().registerMail();
        transport.connect(
                properties.getProperty("mail.smtp.host"),
                properties.getProperty("mail.smtp.username"),
                properties.getProperty("mail.smtp.password"));
        transport.sendMessage(message, message.getAllRecipients());
    } finally {
        transport.close();
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:43,代碼來源:NotificationMail.java

示例14: processEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 * Send Emails to all the registered email id
 * 
 * @param emailData Instance of EmailData
 */
// Why a separate method & class EmailData needed???
private void processEmail(EmailData emailData) {
  if (logger.isTraceEnabled()) {
    logger.trace("Entered MailManager:processEmail");
  }

  if (mailHost == null || mailHost.length() == 0 || emailData == null
      || mailToAddresses.length == 0) {
    logger.error(LocalizedMessage
        .create(LocalizedStrings.MailManager_REQUIRED_MAILSERVER_CONFIGURATION_NOT_SPECIFIED));
    if (logger.isDebugEnabled()) {
      logger.debug("Exited MailManager:processEmail: Not sending email as conditions not met");
    }
    return;
  }

  Session session = Session.getDefaultInstance(getMailHostConfiguration());
  MimeMessage mimeMessage = new MimeMessage(session);
  String subject = emailData.subject;
  String message = emailData.message;
  String mailToList = getMailToAddressesAsString();

  try {
    for (int i = 0; i < mailToAddresses.length; i++) {
      mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(mailToAddresses[i]));
    }

    if (subject == null) {
      subject = LocalizedStrings.MailManager_ALERT_MAIL_SUBJECT.toLocalizedString();
    }
    mimeMessage.setSubject(subject);

    if (message == null) {
      message = "";
    }
    mimeMessage.setText(message);

    Transport.send(mimeMessage);
    logger.info(
        LocalizedMessage.create(LocalizedStrings.MailManager_EMAIL_ALERT_HAS_BEEN_SENT_0_1_2,
            new Object[] {mailToList, subject, message}));
  } catch (VirtualMachineError err) {
    SystemFailure.initiateFailure(err);
    // If this ever returns, rethrow the error. We're poisoned
    // now, so don't let this thread continue.
    throw err;
  } catch (Throwable ex) {
    // Whenever you catch Error or Throwable, you must also
    // catch VirtualMachineError (see above). However, there is
    // _still_ a possibility that you are dealing with a cascading
    // error condition, so you also need to check to see if the JVM
    // is still usable:
    SystemFailure.checkFailure();
    StringBuilder buf = new StringBuilder();
    buf.append(LocalizedStrings.MailManager_AN_EXCEPTION_OCCURRED_WHILE_SENDING_EMAIL
        .toLocalizedString());
    buf.append(
        LocalizedStrings.MailManager_UNABLE_TO_SEND_EMAIL_PLEASE_CHECK_YOUR_EMAIL_SETTINGS_AND_LOG_FILE
            .toLocalizedString());
    buf.append("\n\n").append(
        LocalizedStrings.MailManager_EXCEPTION_MESSAGE_0.toLocalizedString(ex.getMessage()));
    buf.append("\n\n").append(
        LocalizedStrings.MailManager_FOLLOWING_EMAIL_WAS_NOT_DELIVERED.toLocalizedString());
    buf.append("\n\t")
        .append(LocalizedStrings.MailManager_MAIL_HOST_0.toLocalizedString(mailHost));
    buf.append("\n\t").append(LocalizedStrings.MailManager_FROM_0.toLocalizedString(mailFrom));
    buf.append("\n\t").append(LocalizedStrings.MailManager_TO_0.toLocalizedString(mailToList));
    buf.append("\n\t").append(LocalizedStrings.MailManager_SUBJECT_0.toLocalizedString(subject));
    buf.append("\n\t").append(LocalizedStrings.MailManager_CONTENT_0.toLocalizedString(message));

    logger.error(buf.toString(), ex);
  }
  if (logger.isTraceEnabled()) {
    logger.trace("Exited MailManager:processEmail");
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:82,代碼來源:MailManager.java

示例15: sendEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的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.MimeMessage.setSubject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。