org.springframework.mail.SimpleMailMessage.setTo()

Here are the examples of the java api org.springframework.mail.SimpleMailMessage.setTo() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

159 Examples 7

19 View Source File : MailService.java
License : Apache License 2.0
Project Creator : zhuoqianmingyue

/**
 * 发送简单的邮件信息
 * @param toMail
 * @param subject
 * @param content
 */
public void sendSimpleMail(String toMail, String subject, String content) {
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setFrom(formMail);
    simpleMailMessage.setTo(toMail);
    simpleMailMessage.setSubject(subject);
    simpleMailMessage.setText(content);
    try {
        sender.send(simpleMailMessage);
        logger.info("发送给" + toMail + "简单邮件已经发送。 subject:" + subject);
    } catch (Exception e) {
        logger.info("发送给" + toMail + "send mail error subject:" + subject);
        e.printStackTrace();
    }
}

19 View Source File : MailTool.java
License : MIT License
Project Creator : zhaopei8948

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();
    }
}

19 View Source File : MailServiceImpl.java
License : Apache License 2.0
Project Creator : zhaoguhong

@Override
public void sendSimleMail(String to, String subject, String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(sender);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    mailSender.send(message);
}

19 View Source File : MailServiceImpl.java
License : GNU General Public License v3.0
Project Creator : zcbin

/**
 * 发送文本邮件
 *
 * @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);
    if (ArrayUtil.isNotEmpty(cc)) {
        message.setCc(cc);
    }
    mailSender.send(message);
}

19 View Source File : SysEmailServiceImpl.java
License : MIT License
Project Creator : yunchaoyun

/**
 * @description
 *  	发送纯文本邮件
 * @params
 *      to        邮件接收方
 *      subject   邮件主题
 *      text      邮件内容
 * @return void
 * @author mhm
 * @time 2019年12月9日 上午10:46:40
 */
public void sendTextMail(String to, String subject, String text) {
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setFrom(from);
    simpleMailMessage.setTo(to);
    simpleMailMessage.setSubject(subject);
    simpleMailMessage.setText(text);
    try {
        javaMailSender.send(simpleMailMessage);
    } catch (Exception e) {
        log.error("邮件发送失败。" + e.getMessage());
    }
}

19 View Source File : MailTool.java
License : Apache License 2.0
Project Creator : xwjie

public void send(String subjct, String text, String... to) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subjct);
    message.setText(text);
    jmsTool.sendMessage(JMSType.SEND_MAIL, message);
}

19 View Source File : ApplicationTests.java
License : Apache License 2.0
Project Creator : xuwujing

@Test
public void sendSimpleMail() throws Exception {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom("[email protected]");
    message.setTo("[email protected]");
    message.setSubject("主题:这是一封测试邮件!");
    message.setText("测试邮件内容");
    mailSender.send(message);
    System.out.println("发送成功!");
}

19 View Source File : MailController.java
License : Apache License 2.0
Project Creator : xuwujing

/*
	 * 发送普通邮件
	 */
@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 "发送成功!";
}

19 View Source File : EmailMessageSender.java
License : GNU Lesser General Public License v3.0
Project Creator : xkcoding

/**
 * 处理简单邮件类型
 *
 * @param message 邮件内容
 * @return boolean
 */
private boolean processSimpleEmail(EmailMessage message) {
    // 注意邮件发送可能出现异常,注意catch
    try {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("\"" + message.getFrom() + "\" <" + username + ">");
        simpleMailMessage.setTo(ArrayUtil.toArray(message.getTos(), String.clreplaced));
        simpleMailMessage.setSubject(message.getSubject());
        simpleMailMessage.setText(message.getContent());
        // 设置抄送人列表
        if (CollUtil.isEmpty(message.getCcs())) {
            simpleMailMessage.setCc(ArrayUtil.toArray(message.getCcs(), String.clreplaced));
        }
        mailSender.send(simpleMailMessage);
        return true;
    } catch (Exception e) {
        log.error("简单邮件发送异常!", e);
        return false;
    }
}

19 View Source File : MailController.java
License : Apache License 2.0
Project Creator : xiaop1ng

@GetMapping("/send")
public Rs sendMail() {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(mailUser);
    message.setTo("[email protected]");
    message.setSubject("主题");
    message.setText("这是内容");
    sender.send(message);
    return Rs.ok();
}

19 View Source File : EmailController.java
License : MIT License
Project Creator : wuyouzhuguli

@RequestMapping("sendSimpleEmail")
public String sendSimpleEmail() {
    try {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        // 接收地址
        message.setTo("[email protected]");
        // 标题
        message.setSubject("一封简单的邮件");
        // 内容
        message.setText("使用Spring Boot发送简单邮件。");
        jms.send(message);
        return "发送成功";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

19 View Source File : MailController.java
License : MIT License
Project Creator : wu-boy

@ApiOperation("发送邮件")
@PostMapping("send")
public BaseResult send(@RequestBody MailMessageDto dto) {
    BaseResult result = new BaseResult();
    if (StringUtils.isBlank(dto.getTo())) {
        result.setData(0);
        result.setMessage("缺少收信人");
        return result;
    }
    if (StringUtils.isBlank(dto.getSubject())) {
        result.setData(0);
        result.setMessage("缺少主题");
        return result;
    }
    if (StringUtils.isBlank(dto.getText())) {
        result.setData(0);
        result.setMessage("缺少内容");
        return result;
    }
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(dto.getTo());
    message.setSubject(dto.getSubject());
    message.setText(dto.getText());
    try {
        javaMailSender.send(message);
    } catch (Exception e) {
        result.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        result.setMessage(e.getMessage());
        log.error("发送邮件参数错误{}", e.getMessage());
        e.printStackTrace();
    }
    return result;
}

19 View Source File : SmtpSender.java
License : MIT License
Project Creator : wolforest

public void send(@NonNull String to, @NonNull String subject, @NonNull String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    mailSender.send(message);
}

19 View Source File : NotifyService.java
License : GNU General Public License v3.0
Project Creator : wlhbdp

/**
 * 邮件消息通知,
 * 接收者在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);
}

19 View Source File : MailHelper.java
License : Apache License 2.0
Project Creator : weiboad

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);
}

19 View Source File : JavaMailSenderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void javaMailSenderWithSimpleMessages() throws MessagingException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPreplacedword("preplacedword");
    SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
    simpleMessage1.setTo("[email protected]");
    SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
    simpleMessage2.setTo("[email protected]");
    sender.send(simpleMessage1, simpleMessage2);
    replacedertEquals("host", sender.transport.getConnectedHost());
    replacedertEquals("username", sender.transport.getConnectedUsername());
    replacedertEquals("preplacedword", sender.transport.getConnectedPreplacedword());
    replacedertTrue(sender.transport.isCloseCalled());
    replacedertEquals(2, sender.transport.getSentMessages().size());
    MimeMessage sentMessage1 = sender.transport.getSentMessage(0);
    List<Address> tos1 = Arrays.asList(sentMessage1.getRecipients(Message.RecipientType.TO));
    replacedertEquals(1, tos1.size());
    replacedertEquals("[email protected]", ((InternetAddress) tos1.get(0)).getAddress());
    MimeMessage sentMessage2 = sender.transport.getSentMessage(1);
    List<Address> tos2 = Arrays.asList(sentMessage2.getRecipients(Message.RecipientType.TO));
    replacedertEquals(1, tos2.size());
    replacedertEquals("she@mail.org", ((InternetAddress) tos2.get(0)).getAddress());
}

19 View Source File : JavaMailSenderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void failedSimpleMessage() throws MessagingException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPreplacedword("preplacedword");
    SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
    simpleMessage1.setTo("[email protected]");
    simpleMessage1.setSubject("fail");
    SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
    simpleMessage2.setTo("[email protected]");
    try {
        sender.send(simpleMessage1, simpleMessage2);
    } catch (MailSendException ex) {
        ex.printStackTrace();
        replacedertEquals("host", sender.transport.getConnectedHost());
        replacedertEquals("username", sender.transport.getConnectedUsername());
        replacedertEquals("preplacedword", sender.transport.getConnectedPreplacedword());
        replacedertTrue(sender.transport.isCloseCalled());
        replacedertEquals(1, sender.transport.getSentMessages().size());
        replacedertEquals(new InternetAddress("[email protected]"), sender.transport.getSentMessage(0).getAllRecipients()[0]);
        replacedertEquals(1, ex.getFailedMessages().size());
        replacedertEquals(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
        Object subEx = ex.getFailedMessages().values().iterator().next();
        replacedertTrue(subEx instanceof MessagingException);
        replacedertEquals("failed", ((MessagingException) subEx).getMessage());
    }
}

19 View Source File : JavaMailSenderTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void javaMailSenderWithSimpleMessage() throws MessagingException, IOException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setPort(30);
    sender.setUsername("username");
    sender.setPreplacedword("preplacedword");
    SimpleMailMessage simpleMessage = new SimpleMailMessage();
    simpleMessage.setFrom("[email protected]");
    simpleMessage.setReplyTo("[email protected]");
    simpleMessage.setTo("[email protected]");
    simpleMessage.setCc("[email protected]", "[email protected]");
    simpleMessage.setBcc("[email protected]", "[email protected]");
    Date sentDate = new GregorianCalendar(2004, 1, 1).getTime();
    simpleMessage.setSentDate(sentDate);
    simpleMessage.setSubject("my subject");
    simpleMessage.setText("my text");
    sender.send(simpleMessage);
    replacedertEquals("host", sender.transport.getConnectedHost());
    replacedertEquals(30, sender.transport.getConnectedPort());
    replacedertEquals("username", sender.transport.getConnectedUsername());
    replacedertEquals("preplacedword", sender.transport.getConnectedPreplacedword());
    replacedertTrue(sender.transport.isCloseCalled());
    replacedertEquals(1, sender.transport.getSentMessages().size());
    MimeMessage sentMessage = sender.transport.getSentMessage(0);
    List<Address> froms = Arrays.asList(sentMessage.getFrom());
    replacedertEquals(1, froms.size());
    replacedertEquals("[email protected]", ((InternetAddress) froms.get(0)).getAddress());
    List<Address> replyTos = Arrays.asList(sentMessage.getReplyTo());
    replacedertEquals("[email protected]", ((InternetAddress) replyTos.get(0)).getAddress());
    List<Address> tos = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.TO));
    replacedertEquals(1, tos.size());
    replacedertEquals("[email protected]", ((InternetAddress) tos.get(0)).getAddress());
    List<Address> ccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.CC));
    replacedertEquals(2, ccs.size());
    replacedertEquals("[email protected]", ((InternetAddress) ccs.get(0)).getAddress());
    replacedertEquals("[email protected]", ((InternetAddress) ccs.get(1)).getAddress());
    List<Address> bccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.BCC));
    replacedertEquals(2, bccs.size());
    replacedertEquals("[email protected]", ((InternetAddress) bccs.get(0)).getAddress());
    replacedertEquals("[email protected]", ((InternetAddress) bccs.get(1)).getAddress());
    replacedertEquals(sentDate.getTime(), sentMessage.getSentDate().getTime());
    replacedertEquals("my subject", sentMessage.getSubject());
    replacedertEquals("my text", sentMessage.getContent());
}

19 View Source File : MailServiceImpl.java
License : Apache License 2.0
Project Creator : vanDusty

@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);
}

19 View Source File : ApplicationTests.java
License : Apache License 2.0
Project Creator : ukihsoroy

@Test
public void sendSimpleMail() throws Exception {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(from);
    message.setSubject("主题:简单邮件");
    message.setText("测试邮件内容");
    mailSender.send(message);
}

19 View Source File : EmailService.java
License : Apache License 2.0
Project Creator : u014427391

/**
 *  发送文本邮件
 * @Author mazq
 * @Date 2020/07/22 16:31
 * @Param [email]
 * @return
 */
public void sendTextMail(EmailDto email) {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setTo(email.getSendTo());
    mailMessage.setSubject(email.getSubject());
    mailMessage.setText(email.getContent());
    mailMessage.setFrom(mailProperties.getUsername());
    javaMailSender.send(mailMessage);
}

19 View Source File : MailServiceImpl.java
License : Apache License 2.0
Project Creator : TDuckCloud

/**
 * 发送文本邮件
 *
 * @param toAddr
 * @param replacedle
 * @param content
 */
@Override
public void sendTextMail(String toAddr, String replacedle, String content) {
    // 纯文本邮件对象
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(toAddr);
    message.setSubject(replacedle);
    message.setText(content);
    try {
        mailSender.send(message);
        log.info("Text邮件已经发送。");
    } catch (Exception e) {
        log.error("发送Text邮件时发生异常!", e);
    }
}

19 View Source File : BenchmarkLauncher.java
License : GNU General Public License v3.0
Project Creator : straumat

@Override
public final void run() {
    log.info("24 hours benchmark started");
    // Waiting 24 hours.
    try {
        Thread.sleep(BENCHMARK_DURATION);
    } catch (InterruptedException e) {
        log.error("Benchmark interrupted " + e.getMessage(), e);
    }
    // get build number
    String buildNumber = "Not Available";
    if (System.getenv(BUILD_NUMBER_PARAMETER) != null) {
        buildNumber = System.getenv(BUILD_NUMBER_PARAMETER);
    }
    // Get the number of blocks imported and sending report.
    long blockCount = repositories.getBlockRepository().count();
    log.info("Benchmark finished - {} blocks imported", blockCount);
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom("[email protected]");
    message.setTo("[email protected]");
    message.setSubject("B2G benchmark results for build number : " + buildNumber);
    message.setText("Number of blocks imported : " + blockCount);
    getJavaMailSender().send(message);
    log.info("Benchmark maid sent");
    // We stop the application.
    log.info("Application exit");
    SpringApplication.exit(context, () -> 0);
}

19 View Source File : TodoSharingListener.java
License : Apache License 2.0
Project Creator : stratospheric-dev

@SqsListener(value = "${custom.sharing-queue}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void listenToSharingMessages(TodoCollaborationNotification payload) {
    LOG.info("Incoming todo sharing payload: {}", payload);
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom("[email protected]");
    message.setTo(payload.getCollaboratorEmail());
    message.setSubject("A todo was shared with you");
    message.setText(String.format("Hi %s, \n\n" + "someone shared a Todo from https://app.stratospheric.dev with you.\n\n" + "Information about the shared Todo item: \n\n" + "replacedle: %s \n" + "Description: %s \n" + "Priority: %s \n" + "\n" + "You can accept the collaboration by clicking this link: " + "https://app.stratospheric.dev/todo/%s/collaborations/%s/confirm?token=%s " + "\n\n" + "Kind regards, \n" + "Stratospheric", payload.getCollaboratorEmail(), payload.getTodoreplacedle(), payload.getTodoDescription(), payload.getTodoPriority(), payload.getTodoId(), payload.getCollaboratorId(), payload.getToken()));
    mailSender.send(message);
    LOG.info("Successfully informed collaborator about shared todo");
    if (Arrays.asList(environment.getActiveProfiles()).contains("dev")) {
        LOG.info("Auto-confirmed collaboration request");
        todoCollaborationService.confirmCollaboration(payload.getTodoId(), payload.getCollaboratorId(), payload.getToken());
    }
}

19 View Source File : TodoSharingListener.java
License : Apache License 2.0
Project Creator : stratospheric-dev

@SqsListener(value = "${custom.sharing-queue}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void listenToSharingMessages(TodoCollaborationNotification payload) {
    LOG.info("Incoming todo sharing payload: {}", payload);
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom("[email protected]");
    message.setTo(payload.getCollaboratorEmail());
    message.setSubject("A todo was shared with you");
    message.setText(String.format("Hi %s, \n\n" + "someone shared a Todo from https://app.stratospheric.dev with you.\n\n" + "Information about the shared Todo item: \n\n" + "replacedle: %s \n" + "Description: %s \n" + "Priority: %s \n" + "\n" + "You can accept the collaboration by clicking this link: " + "https://app.stratospheric.dev/todo/%s/collaborations/%s/confirm?token=%s " + "\n\n" + "Kind regards, \n" + "Stratospheric", payload.getCollaboratorEmail(), payload.getTodoreplacedle(), payload.getTodoDescription(), payload.getTodoPriority(), payload.getTodoId(), payload.getCollaboratorId(), payload.getToken()));
    mailSender.send(message);
    LOG.info("Successfully informed collaborator about shared todo.");
    if (Arrays.asList(environment.getActiveProfiles()).contains("dev")) {
        LOG.info("Auto-confirmed collaboration request for todo: {}", payload.getTodoId());
        todoCollaborationService.confirmCollaboration(payload.getTodoId(), payload.getCollaboratorId(), payload.getToken());
    }
}

19 View Source File : Mailer.java
License : MIT License
Project Creator : springboilerplate

private final SimpleMailMessage constructResendVerificationTokenEmail(final AppUser user, final VerificationToken newToken) {
    SimpleMailMessage email = new SimpleMailMessage();
    email.setTo(user.getEmail());
    email.setSubject("Resend Registration Token");
    email.setText("New token is " + newToken.getToken());
    email.setFrom(env.getProperty("support.email"));
    return email;
}

19 View Source File : Mailer.java
License : MIT License
Project Creator : springboilerplate

private final SimpleMailMessage constructRegistrationEmailMessage(final OnRegistrationCompleteEvent event, final AppUser user, final String token) {
    final String recipientAddress = user.getEmail();
    final String subject = "Registration Confirmation";
    // final String confirmationUrl = event.getAppUrl() +
    // "/registrationConfirm.html?token=" + token;
    // final String message = messages.getMessage("message.regSucc", null,
    // event.getLocale());
    final SimpleMailMessage email = new SimpleMailMessage();
    email.setTo(recipientAddress);
    email.setSubject(subject);
    // just sending token
    email.setText("Token is " + token);
    email.setFrom(env.getProperty("support.email"));
    return email;
}

19 View Source File : Mailer.java
License : MIT License
Project Creator : springboilerplate

private final SimpleMailMessage constructResetTokenEmail(final AppUser user, final String preplacedwordToken) {
    SimpleMailMessage email = new SimpleMailMessage();
    email.setTo(user.getEmail());
    email.setSubject("Reset Preplacedword Token");
    email.setText("New token is " + preplacedwordToken);
    email.setFrom(env.getProperty("support.email"));
    return email;
}

19 View Source File : JavamailService.java
License : Apache License 2.0
Project Creator : spring-projects-experimental

@GetMapping("/")
public String send() {
    try {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo("[email protected]");
        message.setFrom("[email protected]");
        message.setSubject("My very email");
        message.setText("Very nice content!");
        javaMailSender.send(message);
    } catch (MailException e) {
    // This is ok as we don't have any server available
    }
    return "OK";
}

19 View Source File : JavaMailSenderTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void javaMailSenderWithSimpleMessage() throws MessagingException, IOException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setPort(30);
    sender.setUsername("username");
    sender.setPreplacedword("preplacedword");
    SimpleMailMessage simpleMessage = new SimpleMailMessage();
    simpleMessage.setFrom("[email protected]");
    simpleMessage.setReplyTo("[email protected]");
    simpleMessage.setTo("[email protected]");
    simpleMessage.setCc("[email protected]", "[email protected]");
    simpleMessage.setBcc("[email protected]", "[email protected]");
    Date sentDate = new GregorianCalendar(2004, 1, 1).getTime();
    simpleMessage.setSentDate(sentDate);
    simpleMessage.setSubject("my subject");
    simpleMessage.setText("my text");
    sender.send(simpleMessage);
    replacedertThat(sender.transport.getConnectedHost()).isEqualTo("host");
    replacedertThat(sender.transport.getConnectedPort()).isEqualTo(30);
    replacedertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
    replacedertThat(sender.transport.getConnectedPreplacedword()).isEqualTo("preplacedword");
    replacedertThat(sender.transport.isCloseCalled()).isTrue();
    replacedertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
    MimeMessage sentMessage = sender.transport.getSentMessage(0);
    List<Address> froms = Arrays.asList(sentMessage.getFrom());
    replacedertThat(froms.size()).isEqualTo(1);
    replacedertThat(((InternetAddress) froms.get(0)).getAddress()).isEqualTo("[email protected]");
    List<Address> replyTos = Arrays.asList(sentMessage.getReplyTo());
    replacedertThat(((InternetAddress) replyTos.get(0)).getAddress()).isEqualTo("[email protected]");
    List<Address> tos = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.TO));
    replacedertThat(tos.size()).isEqualTo(1);
    replacedertThat(((InternetAddress) tos.get(0)).getAddress()).isEqualTo("[email protected]");
    List<Address> ccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.CC));
    replacedertThat(ccs.size()).isEqualTo(2);
    replacedertThat(((InternetAddress) ccs.get(0)).getAddress()).isEqualTo("[email protected]");
    replacedertThat(((InternetAddress) ccs.get(1)).getAddress()).isEqualTo("[email protected]");
    List<Address> bccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.BCC));
    replacedertThat(bccs.size()).isEqualTo(2);
    replacedertThat(((InternetAddress) bccs.get(0)).getAddress()).isEqualTo("[email protected]");
    replacedertThat(((InternetAddress) bccs.get(1)).getAddress()).isEqualTo("[email protected]");
    replacedertThat(sentMessage.getSentDate().getTime()).isEqualTo(sentDate.getTime());
    replacedertThat(sentMessage.getSubject()).isEqualTo("my subject");
    replacedertThat(sentMessage.getContent()).isEqualTo("my text");
}

19 View Source File : JavaMailSenderTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void javaMailSenderWithSimpleMessages() throws MessagingException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPreplacedword("preplacedword");
    SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
    simpleMessage1.setTo("[email protected]");
    SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
    simpleMessage2.setTo("[email protected]");
    sender.send(simpleMessage1, simpleMessage2);
    replacedertThat(sender.transport.getConnectedHost()).isEqualTo("host");
    replacedertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
    replacedertThat(sender.transport.getConnectedPreplacedword()).isEqualTo("preplacedword");
    replacedertThat(sender.transport.isCloseCalled()).isTrue();
    replacedertThat(sender.transport.getSentMessages().size()).isEqualTo(2);
    MimeMessage sentMessage1 = sender.transport.getSentMessage(0);
    List<Address> tos1 = Arrays.asList(sentMessage1.getRecipients(Message.RecipientType.TO));
    replacedertThat(tos1.size()).isEqualTo(1);
    replacedertThat(((InternetAddress) tos1.get(0)).getAddress()).isEqualTo("[email protected]");
    MimeMessage sentMessage2 = sender.transport.getSentMessage(1);
    List<Address> tos2 = Arrays.asList(sentMessage2.getRecipients(Message.RecipientType.TO));
    replacedertThat(tos2.size()).isEqualTo(1);
    replacedertThat(((InternetAddress) tos2.get(0)).getAddress()).isEqualTo("[email protected]");
}

19 View Source File : JavaMailSenderTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void failedSimpleMessage() throws MessagingException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPreplacedword("preplacedword");
    SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
    simpleMessage1.setTo("[email protected]");
    simpleMessage1.setSubject("fail");
    SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
    simpleMessage2.setTo("[email protected]");
    try {
        sender.send(simpleMessage1, simpleMessage2);
    } catch (MailSendException ex) {
        ex.printStackTrace();
        replacedertThat(sender.transport.getConnectedHost()).isEqualTo("host");
        replacedertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
        replacedertThat(sender.transport.getConnectedPreplacedword()).isEqualTo("preplacedword");
        replacedertThat(sender.transport.isCloseCalled()).isTrue();
        replacedertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
        replacedertThat(sender.transport.getSentMessage(0).getAllRecipients()[0]).isEqualTo(new InternetAddress("[email protected]"));
        replacedertThat(ex.getFailedMessages().size()).isEqualTo(1);
        replacedertThat(ex.getFailedMessages().keySet().iterator().next()).isEqualTo(simpleMessage1);
        Object subEx = ex.getFailedMessages().values().iterator().next();
        boolean condition = subEx instanceof MessagingException;
        replacedertThat(condition).isTrue();
        replacedertThat(((MessagingException) subEx).getMessage()).isEqualTo("failed");
    }
}

19 View Source File : MailServiceImpl.java
License : Apache License 2.0
Project Creator : sofastack

/**
 * 发送文本邮件
 *
 * @param toAddr
 * @param replacedle
 * @param content
 */
@Override
public void sendTextMail(String toAddr, String replacedle, String content) {
    // 纯文本邮件对象
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(from);
    message.setTo(toAddr);
    message.setSubject(replacedle);
    message.setText(content);
    try {
        mailSender.send(message);
    } catch (Exception e) {
        logger.error("发送邮件时发生异常!", e);
    }
}

19 View Source File : Mailer.java
License : MIT License
Project Creator : socialsoftware

public void sendSimpleMail(String from, String to, String subject, String body) {
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setFrom(from);
    simpleMailMessage.setTo(to);
    simpleMailMessage.setSubject(subject);
    simpleMailMessage.setText(body);
    if (!host.equals("fake-host") && (to != null && to.trim().length() != 0)) {
        mailSender.send(simpleMailMessage);
    } else if (to == null || to.trim().length() == 0) {
        logger.info("email address was null or empty: {}, {}, {}, {}", from, to, subject, body);
    } else if (host.equals("fake-host")) {
        logger.info("email not send due to fake host configuration: {}, {}, {}, {}", from, to, subject, body);
    }
}

19 View Source File : MailServiceImpl.java
License : MIT License
Project Creator : smltq

/**
 * 发送文本邮件
 *
 * @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);
}

19 View Source File : EmailSendMsgHandle.java
License : MIT License
Project Creator : smallyunet

@Override
public void SendMsg(String es_receiver, String es_replacedle, String es_content) {
    JavaMailSender mailSender = (JavaMailSender) SpringContextUtils.getBean("mailSender");
    SimpleMailMessage message = new SimpleMailMessage();
    // 设置发送方邮箱地址
    message.setFrom(emailFrom);
    message.setTo(es_receiver);
    message.setSubject(es_replacedle);
    message.setText(es_content);
    mailSender.send(message);
}

19 View Source File : EmailService.java
License : Apache License 2.0
Project Creator : skalogs

public void send(String destination, String subject, String message) throws MailException {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setFrom("[email protected]");
    msg.setTo(destination);
    msg.setSubject(subject);
    msg.setText(message);
    emailSender.send(msg);
}

19 View Source File : MallWebapiApplicationTests.java
License : GNU General Public License v3.0
Project Creator : silently9527

@Test
public void test() {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom("[email protected]");
    message.setTo("[email protected]");
    message.setSubject("烂尾楼发完了");
    message.setText("违法违规");
    mailSender.send(message);
}

19 View Source File : MailServiceImpl.java
License : Apache License 2.0
Project Creator : ShuaiMou

/**
 * 功能:发送验证码到待注册用户,并保存到redis缓存中
 *
 * @param to 邮件接收方
 */
@Override
@Async
public void sendVerificationCodeEmail(String to) {
    SimpleMailMessage message = new SimpleMailMessage();
    String verificationCode = GenerateVerificationCodeUtils.generateCode();
    String content = "dear user, this is your verification code: " + verificationCode + "   " + "this code will expire 5 minutes";
    message.setFrom(mailFrom);
    message.setTo(to);
    message.setSubject("verification");
    message.setText(content);
    mailSender.send(message);
    LOGGER.info("the verification code has been sent to user: " + to);
    redisUtils.set(to, verificationCode);
    redisUtils.expire(to, 60 * 5);
}

19 View Source File : MailServiceImpl.java
License : Apache License 2.0
Project Creator : ShuaiMou

/**
 * 功能:发送欢迎用户邮件
 *
 * @param to 注册用户邮箱
 * @param subject 主题
 * @param content 邮件内容
 */
@Override
public void sendWelcomeEmail(String to, String subject, String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(mailFrom);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    mailSender.send(message);
    LOGGER.info("user: " + to + " registered successfully");
}

19 View Source File : ShWorkflow.java
License : GNU General Public License v3.0
Project Creator : ShioCMS

public String sendWorkflowEmail(ShWorkflowTask shWorkflowTask) {
    try {
        String replacedle = "";
        if (shWorkflowTask.getShObject() instanceof ShPost) {
            ShPostImpl shPost = (ShPostImpl) shWorkflowTask.getShObject();
            replacedle = shPost.getreplacedle();
        } else if (shWorkflowTask.getShObject() instanceof ShFolder) {
            ShFolder shFolder = (ShFolder) shWorkflowTask.getShObject();
            replacedle = shFolder.getName();
        }
        List<ShGroup> shGroups = new ArrayList<>();
        ShGroup shGroup = shGroupRepository.findByName(shWorkflowTask.getRequested());
        shGroups.add(shGroup);
        Set<ShUser> shUsers = shUserRepository.findByShGroupsIn(shGroups);
        for (ShUser shUser : shUsers) {
            SimpleMailMessage msg = new SimpleMailMessage();
            msg.setTo(shUser.getEmail());
            msg.setSubject("New publish request");
            msg.setText(String.format("Hi %s,%n There a new publish request for content: %s", shUser.getFirstName(), replacedle));
            javaMailSender.send(msg);
        }
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Test Connection Email failed");
        }
    }
    return null;
}

19 View Source File : MailService.java
License : Apache License 2.0
Project Creator : SanShanYouJiu

/**
 * 发送邮件
 * @param email   邮箱
 * @param text    内容
 * @param subject 标题
 */
private void sendEmail(String email, String text, String subject) {
    // 构建简单邮件对象
    SimpleMailMessage smm = new SimpleMailMessage();
    // 设定邮件参数
    smm.setTo(email);
    smm.setFrom(javaMailSender.getUsername());
    smm.setSubject(subject);
    smm.setText(text);
    // 发送邮件
    pool.execute(() -> {
        javaMailSender.send(smm);
        log.info("Email:{}发送成功", email);
    });
    log.info("已发送邮件:{}", email);
}

19 View Source File : MailServiceImpl.java
License : MIT License
Project Creator : rstyro

/**
 * 发送文本邮件
 * @param to
 * @param subject
 * @param content
 */
@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);
    }
}

19 View Source File : MailApplicationTest.java
License : MIT License
Project Creator : rexlin600

@Test
public void contextTest() {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setFrom(from);
    mailMessage.setTo("[email protected]");
    mailMessage.setSubject("Simple Mail Test");
    mailMessage.setText("Test mail content");
    javaMailSender.send(mailMessage);
}

19 View Source File : MailService.java
License : MIT License
Project Creator : qufei1993

/**
 * 发送文本邮件
 * @param to
 * @param subject
 * @param content
 */
public void sendTextMail(String to, String subject, String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    // 发送对象
    message.setTo(to);
    // 邮件主题
    message.setSubject(subject);
    // 邮件内容
    message.setText(content);
    // 邮件的发起者
    message.setFrom(from);
    javaMailSender.send(message);
}

19 View Source File : NotifyService.java
License : GNU Lesser General Public License v3.0
Project Creator : qiguliuxing

/**
 * 邮件消息通知, 接收者在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);
}

19 View Source File : SendEmailServiceImpl.java
License : Apache License 2.0
Project Creator : pro-cloud

@Override
public boolean sendTextMail(String subject, String content, String toAddress) {
    boolean bool = true;
    try {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromAddress);
        message.setTo(toAddress);
        message.setSubject(subject);
        message.setText(content);
        sender.send(message);
    } catch (Exception e) {
        bool = false;
        log.error("sendTextMail发送邮件失败!", e);
    }
    return bool;
}

19 View Source File : SendEmailServiceImpl.java
License : Apache License 2.0
Project Creator : pro-cloud

@Override
public boolean sendTextMail(String subject, String content, String toAddress, String... toCCAddress) {
    boolean bool = true;
    try {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromAddress);
        message.setTo(toAddress);
        message.setCc(toCCAddress);
        message.setSubject(subject);
        message.setText(content);
        sender.send(message);
    } catch (Exception e) {
        bool = false;
        log.error("sendTextMail发送邮件失败!", e);
    }
    return bool;
}

19 View Source File : MailAlarmService.java
License : Apache License 2.0
Project Creator : PowerJob

@Override
public void onFailed(Alarm alarm, List<UserInfoDO> targetUserList) {
    initFrom();
    if (CollectionUtils.isEmpty(targetUserList) || javaMailSender == null || StringUtils.isEmpty(from)) {
        return;
    }
    SimpleMailMessage sm = new SimpleMailMessage();
    try {
        sm.setFrom(from);
        sm.setTo(targetUserList.stream().map(UserInfoDO::getEmail).filter(Objects::nonNull).toArray(String[]::new));
        sm.setSubject(alarm.fetchreplacedle());
        sm.setText(alarm.fetchContent());
        javaMailSender.send(sm);
    } catch (Exception e) {
        log.warn("[MailAlarmService] send mail failed, reason is {}", e.getMessage());
    }
}

19 View Source File : Application.java
License : MIT License
Project Creator : PacktPublishing

public void sendMail(String email) {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setTo(email);
    mailMessage.setSubject("Registration");
    mailMessage.setText("Successfully Registered");
    javaMailService.send(mailMessage);
}

See More Examples