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


Java SimpleMailMessage類代碼示例

本文整理匯總了Java中org.springframework.mail.SimpleMailMessage的典型用法代碼示例。如果您正苦於以下問題:Java SimpleMailMessage類的具體用法?Java SimpleMailMessage怎麽用?Java SimpleMailMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: sendRegistrationSuccessEmailSMTP

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
@Test
public void sendRegistrationSuccessEmailSMTP() {
    ReflectionTestUtils.setField(sut, "mailEnabled", true);

    String email = "[email protected]";
    String subject = "Your registration was successful";
    String expected = "Hello!\nYour registration was accepted by an administrator";

    sut.sendSuccessEmail(email, "registration");

    ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
    verify(sender, times(1)).send(captor.capture());
    SimpleMailMessage message = captor.getValue();


    assertEquals(1, message.getTo().length);
    assertEquals(email, message.getTo()[0]);
    assertEquals(subject, message.getSubject());
    assertEquals(expected, message.getText());
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:21,代碼來源:EmailTest.java

示例2: doRun

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
@Override
public void doRun(Collection<HealthCheck> healthChecks) {
    if (!healthChecks.isEmpty()) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setSubject(subjectPrefix + " : " + healthChecks.size() + " failing checks");
        message.setTo(to);

        message.setText(buildMailContent(healthChecks));

        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        sender.setHost(smtpHost);
        sender.setPort(smtpPort);

        userName.ifPresent(name -> sender.setUsername(name));
        pwd.ifPresent(pwd -> sender.setPassword(pwd));

        sender.send(message);
        logger.info("Notification mail sent for " + healthChecks.size() + " health checks");
    }
}
 
開發者ID:gilles-stragier,項目名稱:quickmon,代碼行數:22,代碼來源:MailNotifier.java

示例3: send

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
/**
 * Sends e-mail using Velocity template for the body and the properties
 * passed in as Velocity variables.
 *
 * @param msg The e-mail message to be sent, except for the body.
 * @param hTemplateVariables Variables to use when processing the template.
 */
protected void send(SimpleMailMessage msg, String language, String template, Map<String, Object> hTemplateVariables) {

    LOG.info("Send email ...");
    MimeMessagePreparator preparator = (MimeMessage mimeMessage) -> {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
        message.setTo(msg.getTo());
        message.setFrom(msg.getFrom());
        message.setSubject(msg.getSubject());

        String body = VelocityEngineUtils.mergeTemplateIntoString(
                velocityEngine, 
                "/" + template + "." + language + ".vm", 
                "UTF-8", 
                hTemplateVariables);

        LOG.log(Level.INFO, "Body: {0}", body);

        message.setText(body, true);
    };

    mailSender.send(preparator);

    LOG.log(Level.INFO, "Sender {0}", msg.getFrom());
    LOG.log(Level.INFO, "Recipient {0}", msg.getTo());
}
 
開發者ID:lordoftheflies,項目名稱:wonderjameeee,代碼行數:33,代碼來源:VelocityEmailSender.java

示例4: sendMailAsBcc

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
/**
 * 指定された宛先一覧に BCC で一括送信します。
 *
 * @param recipients 宛先一覧
 * @param subject    件名
 * @param text       本文
 */
@Async
public void sendMailAsBcc(List<String> recipients, String subject, String text) {
    if (recipients.isEmpty()) {
        throw new IllegalArgumentException("recipients is empty.");
    }
    SimpleMailMessage message = new SimpleMailMessage();
    message.setReplyTo(appReply);
    message.setBcc(recipients.toArray(new String[recipients.size()]));
    message.setSubject(subject);
    message.setText(text);
    try {
        mailSender.send(message);
    } catch (MailException e) {
        exceptionHandler.accept(e);
    }
}
 
開發者ID:JavaTrainingCourse,項目名稱:obog-manager,代碼行數:24,代碼來源:MailService.java

示例5: sendAttendMail

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
/**
 * 登録完了メールを送信します。
 *
 * @param membership  メンバー情報
 * @param convocation 対象のイベント招待
 */
@Async
void sendAttendMail(Membership membership, Convocation convocation) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setReplyTo(appReply);
    message.setBcc(appReply);
    message.setTo(membership.getEmail());
    message.setSubject("【登録完了】" + convocation.getSubject());
    message.setText(membership.getName() + " さん\n\n" +
            convocation.getSubject() + "の登録が完了しました。\n\n" +
            "詳細の確認・登録內容の変更は以下 URL より行ってください。\n" +
            appUrl + "\n\n" +
            "本メールに関するお問合せ先: " + appReply + "\n" +
            "Java研修 Go研修 OB・OG會");
    try {
        mailSender.send(message);
    } catch (MailException e) {
        exceptionHandler.accept(e);
    }
}
 
開發者ID:JavaTrainingCourse,項目名稱:obog-manager,代碼行數:26,代碼來源:MailService.java

示例6: sendCancelMail

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
/**
 * キャンセル完了メールを送信します。
 *
 * @param membership  メンバー情報
 * @param convocation 対象のイベント招待
 */
@Async
void sendCancelMail(Membership membership, Convocation convocation) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setReplyTo(appReply);
    message.setBcc(appReply);
    message.setTo(membership.getEmail());
    message.setSubject("【キャンセル完了】" + convocation.getSubject());
    message.setText(membership.getName() + " さん\n\n" +
            convocation.getSubject() + "の登録キャンセルが完了しました。\n\n" +
            "詳細の確認・登録內容の変更は以下 URL より行ってください。\n" +
            appUrl + "\n\n" +
            "本メールに関するお問合せ先: " + appReply + "\n" +
            "Java研修 Go研修 OB・OG會");
    try {
        mailSender.send(message);
    } catch (MailException e) {
        exceptionHandler.accept(e);
    }
}
 
開發者ID:JavaTrainingCourse,項目名稱:obog-manager,代碼行數:26,代碼來源:MailService.java

示例7: sendPasswordResetMail

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
/**
 * パスワードリセット案內メールを送信します。
 *
 * @param request パスワードリセット要求
 */
@Async
void sendPasswordResetMail(PasswordResetRequest request) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setReplyTo(appReply);
    message.setTo(request.getMembership().getEmail());
    message.setSubject("【パスワードリセット】Java研修 Go研修 OB・OG會");
    message.setText(request.getMembership().getName() + " さん\n\n" +
            "パスワードリセットの要求を受け付けました。\n" +
            "下記 URL から 24 時間以內にパスワードリセットを行ってください。\n\n" +
            appUrl + "/#!" + ResetPasswordView.VIEW_NAME + "/" + request.getToken() + "\n" +
            "※トップページにリダイレクトされてしまう場合は、トップページを開いた畫麵 (タブ) のアドレス欄に" +
            "上記 URL を張り付けて移動してください。\n\n" +
            "本メールに関するお問合せ先: " + appReply + "\n" +
            "Java研修 Go研修 OB・OG會");
    try {
        mailSender.send(message);
    } catch (MailException e) {
        exceptionHandler.accept(e);
    }
}
 
開發者ID:JavaTrainingCourse,項目名稱:obog-manager,代碼行數:26,代碼來源:MailService.java

示例8: sendUpdateMail

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
/**
 * メンバー情報更新完了メールを送信します。
 *
 * @param membership メンバー情報
 */
@Async
void sendUpdateMail(Membership membership) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setReplyTo(appReply);
    message.setBcc(appReply);
    message.setTo(membership.getEmail());
    message.setSubject("【會員情報編集完了】Java研修 Go研修 OB・OG會");
    message.setText(membership.getName() + " さん\n\n" +
            "會員情報の編集が完了しました。\n\n" +
            "詳細の確認・登録內容の変更は以下 URL より行ってください。\n" +
            appUrl + "\n\n" +
            "本メールに関するお問合せ先: " + appReply + "\n" +
            "Java研修 Go研修 OB・OG會");
    try {
        mailSender.send(message);
    } catch (MailException e) {
        exceptionHandler.accept(e);
    }
}
 
開發者ID:JavaTrainingCourse,項目名稱:obog-manager,代碼行數:25,代碼來源:MailService.java

示例9: sendSimpleMail

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
/**
 * 發送文本郵件
 * @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);
    }

}
 
開發者ID:duanyaxin,項目名稱:springboot-smart,代碼行數:22,代碼來源:MailServiceImpl.java

示例10: send

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
public void send(String fromEmail, String toEmail,String subject, String text) {
    LOG.info("Starting Send...");
    this.templateMessage = new SimpleMailMessage();
    this.templateMessage.setSubject(subject);
    this.templateMessage.setFrom(fromEmail);
    this.templateMessage.setTo(toEmail);

    SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
    msg.setText(text);
    LOG.info(templateMessage.toString());
    try {
        this.mailSender.send(msg);
    } catch (MailException ex) {
        LOG.error(ex.getMessage());
    }
    LOG.info("Finished Send...");
}
 
開發者ID:asmodeirus,項目名稱:BackOffice,代碼行數:18,代碼來源:MailModel.java

示例11: sendVerificationEmailSMTP

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
@Test
public void sendVerificationEmailSMTP() {
    ReflectionTestUtils.setField(sut, "mailEnabled", true);

    String id = "1234567890";
    String email = "[email protected]";
    String subject = "Verify Email";
    String expected = "Hello!\nSomeone has created an account for this email address. If this was not you then " +
            "just ignore this message. If it was you then click the link bellow.\n\n" +
            "http://localhost:8080/api/visitor/verify_email?id=" + id;

    sut.sendVerificationEmail(id, email);

    ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
    verify(sender, times(1)).send(captor.capture());
    SimpleMailMessage message = captor.getValue();


    assertEquals(1, message.getTo().length);
    assertEquals(email, message.getTo()[0]);
    assertEquals(subject, message.getSubject());
    assertEquals(expected, message.getText());
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:24,代碼來源:EmailTest.java

示例12: sendPasswordResetEmailSMTP

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
@Test
public void sendPasswordResetEmailSMTP() {
    ReflectionTestUtils.setField(sut, "mailEnabled", true);

    String id = "1234567890";
    String email = "[email protected]";
    String subject = "Password recovery";
    String expected = "Hello!\nSomeone has requested a password recovery on this email address. If this was not " +
            "you then just ignore this message. If not then click the link bellow.\n\n" +
            "http://localhost:8080/update-password/" + id;

    sut.sendPasswordResetEmail(id, email);

    ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
    verify(sender, times(1)).send(captor.capture());
    SimpleMailMessage message = captor.getValue();


    assertEquals(1, message.getTo().length);
    assertEquals(email, message.getTo()[0]);
    assertEquals(subject, message.getSubject());
    assertEquals(expected, message.getText());
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:24,代碼來源:EmailTest.java

示例13: sendOrganizationChangeSuccessEmailSMTP

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
@Test
public void sendOrganizationChangeSuccessEmailSMTP() {
    ReflectionTestUtils.setField(sut, "mailEnabled", true);

    String email = "[email protected]";
    String subject = "Your organization change was successful";
    String expected = "Hello!\nYour organization change was accepted by an administrator";

    sut.sendSuccessEmail(email, "organization change");

    ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
    verify(sender, times(1)).send(captor.capture());
    SimpleMailMessage message = captor.getValue();


    assertEquals(1, message.getTo().length);
    assertEquals(email, message.getTo()[0]);
    assertEquals(subject, message.getSubject());
    assertEquals(expected, message.getText());
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:21,代碼來源:EmailTest.java

示例14: sendRegistrationDenialEmailSMTP

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
@Test
public void sendRegistrationDenialEmailSMTP() {
    ReflectionTestUtils.setField(sut, "mailEnabled", true);

    String email = "[email protected]";
    String subject = "Your registration was denied";
    String expected = "Hello!\nYour registration was denied by an administrator";

    sut.sendDenialEmail(email, "registration");

    ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
    verify(sender, times(1)).send(captor.capture());
    SimpleMailMessage message = captor.getValue();

    assertEquals(1, message.getTo().length);
    assertEquals(email, message.getTo()[0]);
    assertEquals(subject, message.getSubject());
    assertEquals(expected, message.getText());
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:20,代碼來源:EmailTest.java

示例15: sendOrganizationChangeDenialEmailSMTP

import org.springframework.mail.SimpleMailMessage; //導入依賴的package包/類
@Test
public void sendOrganizationChangeDenialEmailSMTP() {
    ReflectionTestUtils.setField(sut, "mailEnabled", true);

    String email = "[email protected]";
    String subject = "Your organization change was denied";
    String expected = "Hello!\nYour organization change was denied by an administrator";

    sut.sendDenialEmail(email, "organization change");

    ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
    verify(sender, times(1)).send(captor.capture());
    SimpleMailMessage message = captor.getValue();

    assertEquals(1, message.getTo().length);
    assertEquals(email, message.getTo()[0]);
    assertEquals(subject, message.getSubject());
    assertEquals(expected, message.getText());
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:20,代碼來源:EmailTest.java


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