当前位置: 首页>>代码示例>>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;未经允许,请勿转载。