Java Code Examples for org.springframework.mail.SimpleMailMessage#setFrom()

The following examples show how to use org.springframework.mail.SimpleMailMessage#setFrom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmailUtil.java    From pre with GNU General Public License v3.0 6 votes vote down vote up
public void sendSimpleMail(String to, HttpServletRequest request) {
    SimpleMailMessage message = new SimpleMailMessage();
    //设定邮件参数
    //发送者
    message.setFrom(username);
    //接收者
    message.setTo(to);
    //主题
    message.setSubject("修改pre系统用户邮箱");
    //邮件内容
    // 验证码
    String code = PreUtil.codeGen(4);
    message.setText("【Pre系统】" + ",验证码:" + code + "。" + "你正在使用邮箱验证码修改功能,该验证码仅用于身份验证,请勿透露给他人使用");
    // 发送邮件
    javaMailSender.send(message);
    request.getSession().setAttribute(PreConstant.RESET_MAIL, code.toLowerCase());
}
 
Example 2
Source File: MailTest.java    From SpringBootLearn with Apache License 2.0 6 votes vote down vote up
/**
 * 发送简单邮件
 */
@Test
public void sendSimpleMail() {
    SimpleMailMessage message = new SimpleMailMessage();
    //设定邮件参数
    //发送者
    message.setFrom(username);
    //接收者
    message.setTo("[email protected]");
    //主题
    message.setSubject("测试主题");
    //邮件内容
    message.setText("测试内容");
    // 发送邮件
    javaMailSender.send(message);
}
 
Example 3
Source File: EmailBuilder.java    From common-mvc with MIT License 5 votes vote down vote up
/**
 * 发送简单邮件
 * @param from 发件人
 * @param to 收件人
 * @param subject 主题
 * @param text 正文
 */
public void sendSimpleEmail(String from, String to, String subject, String text){
    SimpleMailMessage message = new SimpleMailMessage();//消息构造器
    message.setFrom(from);//发件人
    message.setTo(to);//收件人
    message.setSubject(subject);//主题
    message.setText(text);//正文
    this.send(message);
}
 
Example 4
Source File: DemoController.java    From seed with Apache License 2.0 5 votes vote down vote up
@GetMapping("/mail")
public CommResult mail(){
    //发送一封简单的邮件
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setFrom(this.mailFrom);
    simpleMailMessage.setTo("[email protected]");
    simpleMailMessage.setSubject("下午开会准时参加");
    simpleMailMessage.setText("15点26楼会议室");
    this.javaMailSender.send(simpleMailMessage);
    //发送一封复杂的邮件
    //注意addInline()里面的"huiyi"要与"cid:huiyi"一致
    //注意addAttachment()方法用于添加附件
    try{
        MimeMessage mimeMessage = this.javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        helper.setFrom(this.mailFrom);
        helper.setTo("[email protected]");
        helper.setSubject("请查收会议纪要");
        helper.setText("<html><body><span style='color:#F00'>会议截图如下,完整图片见附件。</span><br><img src=\\\"cid:huiyi\\\" ></body></html>", true);
        helper.addInline("huiyi", new FileSystemResource(new File("E:\\Jadyer\\Stripes.jpg")));
        helper.addAttachment("会议纪要完整图片.jpg", new FileSystemResource(new File("E:\\Jadyer\\Fedora13.jpg")));
        this.javaMailSender.send(mimeMessage);
    }catch(MessagingException e){
        return CommResult.fail(CodeEnum.SYSTEM_BUSY.getCode(), "邮件发送失败,堆栈轨迹如下:"+ JadyerUtil.extractStackTrace(e));
    }
    return CommResult.success();
}
 
Example 5
Source File: SendOrderConfirmationEmailAdvice.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void afterReturning(Object returnValue, Method m, Object[] args, Object target) throws Throwable {
	Order order = (Order) args[0];
	Account account = ((PetStoreFacade) target).getAccount(order.getUsername());

	// don't do anything if email address is not set
	if (account.getEmail() == null || account.getEmail().length() == 0) {
		return;
	}

	StringBuffer text = new StringBuffer();
	text.append("Dear ").append(account.getFirstName()).append(' ').append(account.getLastName());
	text.append(", thank your for your order from JPetStore. Please note that your order number is ");
	text.append(order.getOrderId());

	SimpleMailMessage mailMessage = new SimpleMailMessage();
	mailMessage.setTo(account.getEmail());
	mailMessage.setFrom(this.mailFrom);
	mailMessage.setSubject(this.subject);
	mailMessage.setText(text.toString());
	try {
		this.mailSender.send(mailMessage);
	}
	catch (MailException ex) {
		// just log it and go on
		logger.warn("An exception occured when trying to send email", ex);
	}
}
 
Example 6
Source File: SendEmailTest.java    From jframework with Apache License 2.0 5 votes vote down vote up
@Test
public void send() {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom("jframework");
    message.setTo("[email protected]");
    message.setSubject("主题:简单邮件");
    message.setText("测试邮件内容");

    mailSender.send(message);
}
 
Example 7
Source File: MailServiceImpl.java    From SpringBoot-Home with Apache License 2.0 5 votes vote down vote up
@Override
public void sendSimpleMail(Mail mail){
    checkMail(mail);
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setFrom(sender);
    mailMessage.setTo(mail.getReceiver());
    mailMessage.setSubject(mail.getSubject());
    mailMessage.setText(mail.getText());
    mailSender.send(mailMessage);
    saveMail(mail);
}
 
Example 8
Source File: SpitterMailServiceImpl.java    From Project with Apache License 2.0 5 votes vote down vote up
@Override
public void sendSimpleSpittleEmail(String to, Spittle spittle) {
	SimpleMailMessage message = new SimpleMailMessage();
	String spitterName = spittle.getSpitter().getFullName();
	message.setFrom("[email protected]");
	message.setTo(to);
	message.setSubject("New spittle from " + spitterName);
	message.setText(spitterName + " says: " + spittle.getText());
	mailSender.send(message);
}
 
Example 9
Source File: NotifyService.java    From mall with MIT License 5 votes vote down vote up
/**
 * 邮件消息通知,
 * 接收者在spring.mail.sendto中指定
 *
 * @param subject 邮件标题
 * @param content 邮件内容
 */
@Async
public void notifyMail(String subject, String content) {
    if (mailSender == null)
        return;

    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(sendFrom);
    message.setTo(sendTo);
    message.setSubject(subject);
    message.setText(content);
    mailSender.send(message);
}
 
Example 10
Source File: MailServiceimpl.java    From ManageBooks with Apache License 2.0 5 votes vote down vote up
@Override
public void sendSimpleMail(String to, String subject, String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    mailSender.send(message);
}
 
Example 11
Source File: MailMessage.java    From Blog with Apache License 2.0 5 votes vote down vote up
public SimpleMailMessage create(String toMail, String subject, String text) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(fromMail);
    message.setTo(toMail);
    message.setSubject(subject);
    message.setText(text);
    return message;
}
 
Example 12
Source File: Controller.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@GetMapping("/send")
public String send() {
	SimpleMailMessage message = new SimpleMailMessage();

	message.setFrom("[email protected]");
	message.setTo("[email protected]");
	message.setSubject("测试邮件");
	message.setText("好好学习");
	javaMailSender.send(message);
	return "hello";
}
 
Example 13
Source File: MailTool.java    From maintain with MIT License 5 votes vote down vote up
public static void sendMail(JavaMailSender mailSender, String from, String to, String subject, String text) {
	try {
		
		SimpleMailMessage message = new SimpleMailMessage();
		message.setFrom(from);// 发送者.
		message.setTo(to);// 接收者.
		message.setSubject(subject);// 邮件主题.
		message.setText(text);// 邮件内容.

		mailSender.send(message);// 发送邮件
		
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 14
Source File: MailServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 发送文本邮件
 *
 * @param to      收件人地址
 * @param subject 邮件主题
 * @param content 邮件内容
 * @param cc      抄送地址
 */
@Override
public void sendSimpleMail(String to, String subject, String content, String... cc) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    message.setCc(cc);

    mailSender.send(message);
}
 
Example 15
Source File: MailHelper.java    From fiery with Apache License 2.0 5 votes vote down vote up
public void sendSimpleMail(String from, String to, String subject, String content) throws Exception {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    mailSender.send(message);
}
 
Example 16
Source File: MailService.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
/**
 * 发送简单文本文件
 */
@Async
public void sendSimpleEmail(final MailDTO dto) {
    try {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(env.getProperty("spring.mail.username"));
        message.setTo(dto.getTos());
        message.setSubject(dto.getSubject());
        message.setText(dto.getContent());
        mailSender.send(message);
        log.info("发送简单文本文件-发送成功!");
    } catch (Exception e) {
        log.error("发送简单文本文件-发生异常: ", e.fillInStackTrace());
    }
}
 
Example 17
Source File: MailSenderAwsTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void send_sendMailWithoutAnyAttachmentUsingTheSimpleMailApi_noExceptionThrownDuringSendAndForget()
		throws Exception {
	SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
	simpleMailMessage.setFrom(this.senderAddress);
	simpleMailMessage.setTo(this.recipientAddress);
	simpleMailMessage.setSubject("test subject");
	simpleMailMessage.setText("test content");

	this.mailSender.send(simpleMailMessage);
}
 
Example 18
Source File: JobService.java    From springboot-sqlite-mini-website with Apache License 2.0 5 votes vote down vote up
public void sendMail(String from, String subject, String message) {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setTo("[email protected]"); //which email you want to send
    mailMessage.setFrom(from);
    mailMessage.setSubject(subject);
    mailMessage.setText(message);
    javaMailSender.send(mailMessage);
    logger.info("Mail sent");
}
 
Example 19
Source File: MailController.java    From springBoot-study with Apache License 2.0 5 votes vote down vote up
@PostMapping("/sendMail")
  public String sendMail(@RequestBody Mail mail) {
  	SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(mail.getSender());
message.setTo(mail.getReceiver());
message.setSubject(mail.getSubject());
message.setText(mail.getText());
mailSender.send(message);
LOG.info("发送成功!");
      return "发送成功!";
  }
 
Example 20
Source File: MailServiceImpl.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
@Override
public void sendSimpleMail(String to, String subject, String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    try {
        mailSender.send(message);
        logger.info("简单邮件已经发送。");
    } catch (Exception e) {
        logger.error("发送简单邮件时发生异常!", e);
    }
}