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


Java JavaMailSenderImpl.createMimeMessage方法代码示例

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


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

示例1: sendMailWithUsername

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的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: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
public void sendMail(final String from, final String to,
    final String subject, final String msg) throws MessagingException {

  // final SimpleMailMessage message = new SimpleMailMessage();
  // message.setFrom(from);
  // message.setTo(to);
  // message.setSubject(subject);
  // message.setText(msg);
  // mailSender.send(message);

  // final JavaMailSenderImpl sender = new JavaMailSenderImpl();
  mailSender = new JavaMailSenderImpl();
  final MimeMessage mimeMessage = mailSender.createMimeMessage();
  final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false,
      "utf-8");
  final String htmlMsg = msg;
  mimeMessage.setContent(htmlMsg, "text/html");
  helper.setTo(to);
  helper.setSubject(subject);
  helper.setFrom(from);
  mailSender.send(mimeMessage);

}
 
开发者ID:AURIN,项目名称:workbenchauth,代码行数:24,代码来源:classMail.java

示例3: sendMailWithNewPassword

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithNewPassword(
        @NotBlank @Email final String email,
        @NotBlank final String newPassword
) {
    log.info("Called with e-mail {}, newPassword {}", email, newPassword);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

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

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:28,代码来源:MailServiceImpl.java

示例4: send

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
public boolean send(String to, String subject, String text, String unsubscribeUrl) {
	try {
		JavaMailSenderImpl sender = (JavaMailSenderImpl) mailSender;
		MimeMessage mail = sender.createMimeMessage();
		mail.setContent(text.replaceAll("\n", "<br\\>\n").trim(),
				"text/html; charset=UTF-8");
		MimeMessageHelper helper = new MimeMessageHelper(mail, false,
				"UTF-8");
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		if (null != unsubscribeUrl) {
			mail.addHeader("List-Unsubscribe", String.format("<%s>", unsubscribeUrl));
		}
		sender.send(mail);
		LOG.trace("E-mail sent with subject: {}", subject);
		return true;
	} catch (Exception ex) {
		LOG.warn("Failed to send email (subject: " + subject + ").", ex);
		return false;
	}
}
 
开发者ID:petabyte-research,项目名称:redflags,代码行数:23,代码来源:EmailSvc.java

示例5: sendEmail

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
public void sendEmail() throws MessagingException {
    String email = backup.getEmail();
    JavaMailSenderImpl mailimpl = new JavaMailSenderImpl();
    mailimpl.setHost("smtp.163.com");
    MimeMessage mailMsg = mailimpl.createMimeMessage();
    MimeMessageHelper msgHelper = new MimeMessageHelper(mailMsg,true,"utf8");
    //set sender,receiver
    msgHelper.setTo(backup.getToemail());
    msgHelper.setFrom(email);
    msgHelper.setSubject("数据库备份");
    msgHelper.setText("<html><head></head><body><h1>数据库备份</h1></body></html>",true);

    msgHelper.addAttachment("study.sql",new File(backup.getSavePath() + File.separator + "study.sql"));
    msgHelper.addAttachment("blog.sql",new File(backup.getSavePath() + File.separator + "blog.sql"));

    mailimpl.setUsername(email);
    mailimpl.setPassword("liubo704");
    Properties prop = new Properties();
    prop.put("mail.smtp.auth",true);
    prop.put("mail.smtp.timeout","25000");

    mailimpl.setJavaMailProperties(prop);
    mailimpl.send(mailMsg);
}
 
开发者ID:ycsoft,项目名称:SweetHeart,代码行数:25,代码来源:BackupController.java

示例6: sendMailWithActivationToken

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithActivationToken(
        @NotBlank @Email final String email,
        @NotBlank final String token
) {
    log.info("Called with e-mail {}, token {}", email, token);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Complete registration");
        helper.setText("To activation your account, click the link below:<br />"
                + "<a href='" + "https://localhost:8443" + "/register/thanks?token=" + token + "'>" +
                "Click here to complete your registration" +
                "</a>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:31,代码来源:MailServiceImpl.java

示例7: sendMailWithEmailChangeToken

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Async
@Override
public void sendMailWithEmailChangeToken(
        @NotBlank @Email final String email,
        @NotBlank final String token
) {
    log.info("Called with e-mail {}, token {}", email, token);

    try {
        final JavaMailSenderImpl sender = new JavaMailSenderImpl();

        final MimeMessage message = sender.createMimeMessage();

        final MimeMessageHelper helper = new MimeMessageHelper(message);

        helper.setTo(email);
        helper.setSubject("Change e-mail");
        helper.setText("Change e-mail address, click the link below:<br />"
                + "<a href='" + "https://localhost:8443" + "/settings/changeEmail/thanks?token=" + token + "'>" +
                "Click here to complete the change of your e-mail" +
                "</a>", true);

        sendMail(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:31,代码来源:MailServiceImpl.java

示例8: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
private void sendMail(JavaMailSenderImpl mailSender, String mailFrom, String email, String subject, String message)
    throws IoTPException {
  try {
    MimeMessage mimeMsg = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, "UTF-8");
    helper.setFrom(mailFrom);
    helper.setTo(email);
    helper.setSubject(subject);
    helper.setText(message, true);
    mailSender.send(helper.getMimeMessage());
  } catch (Exception e) {
    throw handleException(e);
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:15,代码来源:DefaultMailService.java

示例9: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
private void sendMail(JavaMailSenderImpl mailSender, 
        String mailFrom, String email, 
        String subject, String message) throws ThingsboardException {
    try {
        MimeMessage mimeMsg = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, UTF_8);
        helper.setFrom(mailFrom);
        helper.setTo(email);
        helper.setSubject(subject);
        helper.setText(message, true);
        mailSender.send(helper.getMimeMessage());
    } catch (Exception e) {
        throw handleException(e);
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:16,代码来源:DefaultMailService.java

示例10: buildMessage

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
private MimeMessage buildMessage(SUser user, SmtpConfig config, JavaMailSenderImpl sender) throws MessagingException {
    MimeMessage message = sender.createMimeMessage();
    message.setFrom(config.getFromAddress());
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
    message.setSubject("TeamCity password reset");
    message.setText(getMessageBody(user));
    return message;
}
 
开发者ID:dbf256,项目名称:teamcity-password-reset-plugin,代码行数:9,代码来源:PasswordResetController.java

示例11: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
/**
 * 发送邮件 (完整版) (纯JavaMail)
 * 
 * @param toAddress		: 收件人邮箱
 * @param mailSubject	: 邮件主题
 * @param mailBody		: 邮件正文
 * @param mailBodyIsHtml: 邮件正文格式,true:HTML格式;false:文本格式
 * //@param inLineFile	: 内嵌文件
 * @param attachments	: 附件
 */
public static boolean sendMail (String toAddress, String mailSubject, String mailBody, 
		boolean mailBodyIsHtml, File[] attachments){
       try {
		// 创建邮件发送类 JavaMailSender (用于发送多元化邮件,包括附件,图片,html 等)
       	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
       	mailSender.setHost(host); 			// 设置邮件服务主机    
       	mailSender.setUsername(username); 	// 发送者邮箱的用户名    
       	mailSender.setPassword(password); 	// 发送者邮箱的密码    
       	
		// 配置文件,用于实例化java.mail.session
		Properties pro = new Properties();
		pro.put("mail.transport.protocol", "smtp");
		pro.put("mail.smtp.auth", "true");		// 登录SMTP服务器,需要获得授权 (网易163邮箱新近注册的邮箱均不能授权,测试 sohu 的邮箱可以获得授权)
		pro.put("mail.smtp.socketFactory.port", port);
		pro.put("mail.smtp.socketFactory.fallback", "false");
		mailSender.setJavaMailProperties(pro);
		
		// 创建多元化邮件 (创建 mimeMessage 帮助类,用于封装信息至 mimeMessage)
		MimeMessage mimeMessage = mailSender.createMimeMessage();						
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8");
		
		helper.setFrom(username, sendNick);
		helper.setTo(toAddress);

		helper.setSubject(mailSubject);
		helper.setText(mailBody, mailBodyIsHtml); 
		
		// 设置收件人抄送的名片和地址(相当于群发)
		//helper.setCc(InternetAddress.parse(MimeUtility.encodeText("邮箱001") + " <@163.com>," + MimeUtility.encodeText("邮箱002") + " <@foxmail.com>"));

		// 内嵌文件,第1个参数为cid标识这个文件,第2个参数为资源
		//helper.addInline(MimeUtility.encodeText(inLineFile.getName()), inLineFile);
		
		// 添加附件
		/*if (ArrayUtils.isNotEmpty(attachments)) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}*/

		// 群发
		//MimeMessage[] mailMessages = { mimeMessage };
		
		mailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
	return false;
}
 
开发者ID:mmwhd,项目名称:stage-job,代码行数:61,代码来源:MailUtil.java

示例12: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
/**
 * 发送邮件 (完整版) (纯JavaMail)
 * 
 * @param toAddress		: 收件人邮箱
 * @param mailSubject	: 邮件主题
 * @param mailBody		: 邮件正文
 * @param mailBodyIsHtml: 邮件正文格式,true:HTML格式;false:文本格式
 * //@param inLineFile	: 内嵌文件
 * @param attachments	: 附件
 */
public static boolean sendMail (String toAddress, String mailSubject, String mailBody, 
		boolean mailBodyIsHtml, File[] attachments){
       try {
		// 创建邮件发送类 JavaMailSender (用于发送多元化邮件,包括附件,图片,html 等    )
       	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
       	mailSender.setHost(host); 			// 设置邮件服务主机    
       	mailSender.setUsername(username); 	// 发送者邮箱的用户名    
       	mailSender.setPassword(password); 	// 发送者邮箱的密码    
       	
		//配置文件,用于实例化java.mail.session    
		Properties pro = new Properties();
		pro.put("mail.smtp.auth", "true");		// 登录SMTP服务器,需要获得授权 (网易163邮箱新近注册的邮箱均不能授权,测试 sohu 的邮箱可以获得授权)
		pro.put("mail.smtp.socketFactory.port", port);
		pro.put("mail.smtp.socketFactory.fallback", "false");
		mailSender.setJavaMailProperties(pro);
		
		//创建多元化邮件 (创建 mimeMessage 帮助类,用于封装信息至 mimeMessage)
		MimeMessage mimeMessage = mailSender.createMimeMessage();						
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8");
		
		helper.setFrom(sendFrom, sendNick);
		helper.setTo(toAddress);

		helper.setSubject(mailSubject);
		helper.setText(mailBody, mailBodyIsHtml); 
		
		// 添加内嵌文件,第1个参数为cid标识这个文件,第2个参数为资源
		//helper.addInline(MimeUtility.encodeText(inLineFile.getName()), inLineFile);	
		
		// 添加附件    
		if (ArrayUtils.isNotEmpty(attachments)) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}
		
		mailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return false;
}
 
开发者ID:kevinKaiF,项目名称:xxl-job,代码行数:54,代码来源:MailUtil.java

示例13: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //导入方法依赖的package包/类
/**
 * 发送邮件 (完整版) (纯JavaMail)
 * 
 * @param toAddress		: 收件人邮箱
 * @param mailSubject	: 邮件主题
 * @param mailBody		: 邮件正文
 * @param mailBodyIsHtml: 邮件正文格式,true:HTML格式;false:文本格式
 * @param attachments	: 附件
 */
public static boolean sendMail (String toAddress, String mailSubject, String mailBody, 
		boolean mailBodyIsHtml, File[] attachments){
       try {
		// 创建邮件发送类 JavaMailSender (用于发送多元化邮件,包括附件,图片,html 等    )
       	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
       	mailSender.setHost(host); 			// 设置邮件服务主机    
       	mailSender.setUsername(username); 	// 发送者邮箱的用户名    
       	mailSender.setPassword(password); 	// 发送者邮箱的密码    
       	
		//配置文件,用于实例化java.mail.session    
		Properties pro = System.getProperties();
           pro.put("mail.transport.protocol", "smtp");
		pro.put("mail.smtp.auth", "true");		// 登录SMTP服务器,需要获得授权 (网易163邮箱新近注册的邮箱均不能授权,测试 sohu 的邮箱可以获得授权)
		pro.put("mail.smtp.socketFactory.port", port);
		pro.put("mail.smtp.socketFactory.fallback", "false");
		mailSender.setJavaMailProperties(pro);
		
		//创建多元化邮件 (创建 mimeMessage 帮助类,用于封装信息至 mimeMessage)
		MimeMessage mimeMessage = mailSender.createMimeMessage();						
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, (attachments!=null && attachments.length>0), "UTF-8");
		
		helper.setFrom(username, sendNick);
		helper.setTo(toAddress);

		helper.setSubject(mailSubject);
		helper.setText(mailBody, true);

           // 设置收件人抄送的名片和地址(相当于群发)
           //helper.setCc(InternetAddress.parse(MimeUtility.encodeText("邮箱001") + " <@163.com>," + MimeUtility.encodeText("邮箱002") + " <@foxmail.com>"));

		// 添加内嵌文件,第1个参数为cid标识这个文件,第2个参数为资源
		//helper.addInline(MimeUtility.encodeText(inLineFile.getName()), inLineFile);	
		
		// 添加附件    
		if (attachments!=null && attachments.length>0) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}

           // 群发
           //MimeMessage[] mailMessages = { mimeMessage };
		
		mailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return false;
}
 
开发者ID:xuxueli,项目名称:xxl-incubator,代码行数:60,代码来源:MailUtil.java


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