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


Java MimeMessageHelper.setSubject方法代碼示例

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


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

示例1: sendMailWithUsername

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithUsername(
        @NotBlank @Email final String email,
        @NotBlank final String username
) {
    log.info("Called with e-mail {}, username {}", email, username);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Recover username");
        helper.setText("Your username: " + "<b>" + username + "</b>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:28,代碼來源:MailServiceImpl.java

示例2: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
void sendEmail(String to, String subject, String content, String from) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        false, true, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(from);
        message.setSubject(subject);
        message.setText(content, true);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:23,代碼來源:MailService.java

示例3: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        log.warn("Email could not be sent to user '{}'", to, e);
    }
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:20,代碼來源:MailService.java

示例4: sendMailWithTemplate

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Override
public void sendMailWithTemplate(final TemplateMailTO mailParameters) throws MailException {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);

            message.setTo(mailParameters.getToMailAddress());
            message.setFrom(mailParameters.getFromMailAddress());
            message.setSubject(mailParameters.getSubject());
            if (mailParameters.hasCcMailAddress()) {
                message.setCc(mailParameters.getCcMailAddress());
            }
            if (mailParameters.hasReplyTo()) {
                message.setReplyTo(mailParameters.getReplyTo());
            }
            String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, mailParameters.getTemplateLocation(), mailParameters.getTemplateProperties());
            log.debug("*** TEST text='" + text + "'");
            message.setText(text, true);
            message.setValidateAddresses(true);

        }
    };
    this.mailSender.send(preparator);
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:26,代碼來源:MailServiceImpl.java

示例5: sendHtmlMail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * 發送html郵件
 */
@Async("mailAsync")
public void sendHtmlMail(String to, String subject, String content) {
	MimeMessage message = mailSender.createMimeMessage();
	try {
		//true表示需要創建一個multipart message
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		helper.setText(content, true);
		helper.setSentDate(new Date());
		mailSender.send(message);
		logger.info("html郵件發送成功");
	} catch (MessagingException e) {
		logger.error("發送html郵件時發生異常!", e);
	}
}
 
開發者ID:CharleyXu,項目名稱:tulingchat,代碼行數:21,代碼來源:MailUtil.java

示例6: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}'", to, e);
    }
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:20,代碼來源:MailService.java

示例7: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(mailFromDisplay);
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
開發者ID:megadotnet,項目名稱:SpringBootDemoApp,代碼行數:23,代碼來源:MailService.java

示例8: createActivationMail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * creates a activation mail.
 * 
 * may throw a RuntimeException if no MimeMessage can be created
 * 
 * @param activation {@link PendingAccountActivation}  has to contain an id and an UisUser. UisUser should contain an mail address. 
 * @return {@link MimeMessage}
 */
private MimeMessage createActivationMail(PendingAccountActivation activation) throws RuntimeException{
	log.info("creating activation mail for pending activation");
    MimeMessage mimeMsg = mailSender.createMimeMessage();
    MimeMessageHelper msg = new MimeMessageHelper(mimeMsg, "UTF-8");

    try {
        msg.setTo(activation.getForUser().getEmail());
        msg.setSubject(messages.get(MAIL_SUBJECT));
        msg.setText(messageContent(activation), true);
    } catch (MessagingException e) {
    	log.warn("activation message creation FAILED! throwing runtime-exception now");
        throw new RuntimeException(e);
    }

    return msg.getMimeMessage();
}
 
開發者ID:university-information-system,項目名稱:uis,代碼行數:25,代碼來源:UserCreationServiceImpl.java

示例9: createHtmlEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
private static void createHtmlEmail(int i){
    try {
        JavaMailSender sender = getEmailSender();

        MimeMessage message = sender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setTo("[email protected]");
        helper.setFrom("[email protected]");
        helper.setSubject("Test-Mail " + i);
        helper.setText("<html><head></head><body>This is the test mail number " + i + "</body>", true);

        sender.send(message);
    } catch (MessagingException e){
        throw new RuntimeException("Failed to create mail", e);
    }
}
 
開發者ID:gessnerfl,項目名稱:fake-smtp-server,代碼行數:17,代碼來源:TestDataCreator.java

示例10: send

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Override
public void send(NotificationType type, Recipient recipient, String attachment) throws MessagingException, IOException {

	final String subject = env.getProperty(type.getSubject());
	final String text = MessageFormat.format(env.getProperty(type.getText()), recipient.getAccountName());

	MimeMessage message = mailSender.createMimeMessage();

	MimeMessageHelper helper = new MimeMessageHelper(message, true);
	helper.setTo(recipient.getEmail());
	helper.setSubject(subject);
	helper.setText(text);

	if (StringUtils.hasLength(attachment)) {
		helper.addAttachment(env.getProperty(type.getAttachment()), new ByteArrayResource(attachment.getBytes()));
	}

	mailSender.send(message);

	log.info("{} email notification has been send to {}", type, recipient.getEmail());
}
 
開發者ID:sniperqpc,項目名稱:Spring-cloud-gather,代碼行數:22,代碼來源:EmailServiceImpl.java

示例11: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * To send email.
 * 
 * @param mailParam its map containing mail headers details. i.e. "from"
 */  
public void sendEmail(EmailDTO emailDTO) {
	try { 
		if (Objects.nonNull(emailDTO)) {
			MimeMessage  mail = javaMailSenderImpl.createMimeMessage();
			MimeMessageHelper helper = new MimeMessageHelper(mail, true);
			helper.setSubject(emailDTO.getSubject());
			helper.setText(emailDTO.getMessage(), true);
			helper.setFrom(emailDTO.getFrom(), configurationService.getMailConfiguration().getFrom());
			helper.setTo(emailDTO.getTo());
			if (Objects.nonNull(emailDTO.getAttachment())) {
				helper.addAttachment(emailDTO.getAttachmentName(), emailDTO.getAttachment());
			}
			javaMailSenderImpl.send(mail);
		}
	} catch (MessagingException | MailException | UnsupportedEncodingException e) {
		logger.error("Exception while sending mail notification.", e);
	}
}
 
開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:24,代碼來源:EmailService.java

示例12: sendEmail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage());
    }
}
 
開發者ID:RawSanj,項目名稱:blogAggr,代碼行數:20,代碼來源:MailService.java

示例13: sendAttachmentsMail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * 發送帶附件的郵件
 */
@Test
public void sendAttachmentsMail() {
    MimeMessage message = null;
    try {
        message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(Sender);
        helper.setTo(Sender);
        helper.setSubject("主題:帶附件的郵件");
        helper.setText("帶附件的郵件內容");
        //注意項目路徑問題,自動補用項目路徑
        FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/picture.jpg"));
        //加入郵件
        helper.addAttachment("圖片.jpg", file);
    } catch (Exception e) {
        e.printStackTrace();
    }
    mailSender.send(message);
}
 
開發者ID:zhaoshuxue,項目名稱:springBoot,代碼行數:23,代碼來源:UnitTest.java

示例14: sendInlineMail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
/**
 * 發送帶靜態資源的郵件
 */
@Test
public void sendInlineMail() {
    MimeMessage message = null;
    try {
        message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(Sender);
        helper.setTo(Sender);
        helper.setSubject("主題:帶靜態資源的郵件");
        //第二個參數指定發送的是HTML格式,同時cid:是固定的寫法
        helper.setText("<html><body>帶靜態資源的郵件內容 圖片:<img src='cid:picture' /></body></html>", true);

        FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/picture.jpg"));
        helper.addInline("picture", file);
    } catch (Exception e) {
        e.printStackTrace();
    }
    mailSender.send(message);
}
 
開發者ID:zhaoshuxue,項目名稱:springBoot,代碼行數:23,代碼來源:UnitTest.java

示例15: sendAttachmentsMail

import org.springframework.mail.javamail.MimeMessageHelper; //導入方法依賴的package包/類
@Test
public void sendAttachmentsMail() throws Exception {

    MimeMessage mimeMessage = mailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
    helper.setFrom("[email protected]");
    helper.setTo("[email protected]");
    helper.setSubject("主題:有附件");
    helper.setText("有附件的郵件");

    FileSystemResource file = new FileSystemResource(new File("weixin.jpg"));
    helper.addAttachment("附件-1.jpg", file);
    helper.addAttachment("附件-2.jpg", file);

    mailSender.send(mimeMessage);
}
 
開發者ID:xiaomoinfo,項目名稱:SpringBootUnity,代碼行數:18,代碼來源:MailTests.java


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