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


Java SimpleMailMessage.setFrom方法代码示例

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


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

示例1: 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

示例2: 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);
        log.info("邮件发送成功!");
    } catch (Exception e) {
        log.error("邮件发送失败!");
        log.error("失败原因:{}", e);
    }
}
 
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:24,代码来源:MailServiceImpl.java

示例3: sendMail

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
@Override
@Async
// 异步发送邮件
public void sendMail(Comment comment, Article article) {
    if (properties.getNotification()) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(properties.getFrom());
        message.setTo(properties.getTo());
        message.setSubject(properties.getSubject());
        String messageText = properties.getText()
                .replace("author", comment.getAuthor())
                .replace("title", article.getTitle())
                .replace("text", comment.getText())
                .replace("agent", comment.getAgent())
                .replace("ip", Optional.ofNullable(comment.getIp()).orElse(""));
        message.setText(messageText);
        mailSender.send(message);
    }
}
 
开发者ID:fku233,项目名称:Plum,代码行数:20,代码来源:CommentServiceImpl.java

示例4: sendMessage

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
public boolean sendMessage(String mailFrom, String mailTo, String subject, String mailMessage) {
   
   SimpleMailMessage mail = new SimpleMailMessage();  
   
if(this.isEnabled) {
  	try {
   		mail.setFrom(mailFrom);
	    mail.setTo(mailTo);
	    mail.setSubject(subject);
	    mail.setText(mailMessage);
        mailSender.send(mail);
        log.debug("Email sent : " + mail.toString());
        //logService.logMail(mailTo, mailMessage, LogService.MAIL_SENT);
   	} catch(Exception e) {   		
        log.error("Email failed : " + mail.toString(), e);
        //logService.logMail(mailTo, mailMessage, LogService.MAIL_FAILED);
        return false;
   	}
} else {
	log.warn("sendMessage called but email is not enabled ...");
	log.info("\tmethod call was :  sendMessage(" + mailFrom + ", " + mailTo + ", " + subject + ", " + mailMessage + ")");
}
return true;
  }
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:25,代码来源:EmailService.java

示例5: sendSimpleMail

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
/**
 * 发送文本邮件  setCc 抄送 setBcc 密送
 */
@Async("mailAsync")
public void sendSimpleMail(String to, String subject, String content) {
	SimpleMailMessage message = new SimpleMailMessage();
	message.setFrom(from);
	message.setTo(to);
	message.setBcc(from);
	message.setSubject(subject);
	message.setText(content);
	message.setSentDate(new Date());
	try {
		mailSender.send(message);
		logger.info("简单邮件已经发送。");
	} catch (Exception e) {
		logger.error("发送简单邮件时发生异常!", e);
	}

}
 
开发者ID:CharleyXu,项目名称:tulingchat,代码行数:21,代码来源:MailUtil.java

示例6: SendMail

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
public SendMail() {
	mailBean = new MailBean();
	mailSender = new JavaMailSenderImpl();
	mailSender.setPort(mailBean.getPORT());
	mailSender.setHost(mailBean.getHOST());
	mailSender.setUsername(mailBean.getUSERNAME());
	mailSender.setPassword(mailBean.getPASSWORD());
	Properties properties = new Properties();
	properties.setProperty("mail.smtp.auth", "true");
	mailSender.setJavaMailProperties(properties);
	mailMessage = new SimpleMailMessage();
	mailMessage.setFrom(mailBean.getFROM());
	mailMessage.setTo(mailBean.getTO());
	mailMessage.setSubject(mailBean.getSUBJECT());
	GetUserInfo getUserInfo = new GetUserInfo();
	mailMessage.setText("[version]:" + LoadVersion.getVersion() + "\n[javaVersion]:" + getUserInfo.getJavaVersion()
			+ "\n[osName]:" + getUserInfo.getOsName() + "\n[jvmName]:" + getUserInfo.getJvmName() + "\n[address]:"
			+ getUserInfo.getAddress() + "\n[hostName]:" + getUserInfo.getHostname() + "\n[startTime]:"
			+ getUserInfo.getStartTime());
}
 
开发者ID:gaoxianglong,项目名称:shark,代码行数:21,代码来源:SendMail.java

示例7: sendEmailMsg

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
private void sendEmailMsg(String email, String content) {
	logger.info("kaishi");
	JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
       // 设定mail server
       senderImpl.setHost(mailHost);
       senderImpl.setUsername(mailUserName);
       senderImpl.setPassword(mailPassword);

       Properties prop = new Properties();
       // 将这个参数设为true,让服务器进行认证,认证用户名和密码是否正确
       prop.put("mail.smtp.auth", "true");
       prop.put("mail.smtp.timeout", "25000");// milliseconds
       senderImpl.setJavaMailProperties(prop);
       // 建立邮件消息
       SimpleMailMessage mailMessage = new SimpleMailMessage();

       mailMessage.setTo(email);
       mailMessage.setFrom(mailSender);
       mailMessage.setSubject("sam验证码");
       mailMessage.setText(content);

       // 发送邮件
       senderImpl.send(mailMessage);

       logger.info("successfully send mail");
}
 
开发者ID:booleguo,项目名称:sam-elle,代码行数:27,代码来源:EmailSendServiceImpl.java

示例8: sendAlarm

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
public void sendAlarm(AlarmMessage data) {
    SimpleMailMessage mail = new SimpleMailMessage(); // 只发送纯文本
    mail.setText(data.getMessage());// 邮件内容
    mail.setSubject(TITLE);// 主题
    mail.setFrom(emailUsername);

    String receiveKeys[] = StringUtils.split(StringUtils.replace(data.getReceiveKey(), ";", ","), ",");
    List<String> address = new ArrayList<String>();
    for (String receiveKey : receiveKeys) {
        if (isEmailAddress(receiveKey)) {
            address.add(receiveKey);
        } else if (isMobileNumber(receiveKey)) {
            // do nothing
        }
    }

    if (address != null && !address.isEmpty()) {
        mail.setTo(address.toArray(new String[address.size()]));
        sendMail(mail);
    }
}
 
开发者ID:alibaba,项目名称:yugong,代码行数:22,代码来源:MailAlarmService.java

示例9: sendmail

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
@RequestMapping(value = "sendmail", method = RequestMethod.POST, produces = { "application/xml", "application/json" })
public ResponseEntity<Email> sendmail(@RequestBody Email email) {
	JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
	javaMailSender.setHost(email.getHost());
	SimpleMailMessage message = new SimpleMailMessage();
	message.setFrom(email.getFrom());
	message.setTo(email.getTo());
	message.setSubject(email.getSubject());
	message.setText(email.getText());
	try{
		javaMailSender.send(message);
		email.setStatus(true);
	}catch(Exception e){
		email.setText(e.getMessage());
		email.setStatus(false);
	}

	return new ResponseEntity<Email>(email, HttpStatus.OK);
}
 
开发者ID:oscm,项目名称:web,代码行数:20,代码来源:EmailRestController.java

示例10: mail

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
@RequestMapping(value = "mail", method = RequestMethod.POST, produces = { "application/xml", "application/json" })
public ResponseEntity<Email> mail(@RequestBody Email email) {
	SimpleMailMessage message = new SimpleMailMessage();
	message.setFrom(email.getFrom());
	message.setTo(email.getTo());
	message.setSubject(email.getSubject());
	message.setText(email.getText());
	try{
		javaMailSender.send(message);
		email.setStatus(true);
	}catch(Exception e){
		email.setText(e.getMessage());
		email.setStatus(false);
	}
	
	return new ResponseEntity<Email>(email, HttpStatus.OK);
}
 
开发者ID:oscm,项目名称:web,代码行数:18,代码来源:EmailRestController.java

示例11: sendMailToAuthor

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
private Consumer<StreamItemEntity> sendMailToAuthor(MailSender mailSender,
                                                    String markerAuthor,
                                                    String itemId,
                                                    String markerType) {
  return foundItem -> {
    Optional<String> authorMail = ofNullable(foundItem.getAuthor().getEmail());
    if (validMailAddress(authorMail) &&
        !itemAuthorEqualsMarkerAuthor(markerAuthor, foundItem)) {
      SimpleMailMessage mentionMessage = new SimpleMailMessage();
      mentionMessage.setFrom("[email protected]");
      mentionMessage.setSubject("You got a new '" + markerType + "' on a put!");
      mentionMessage.setTo(foundItem.getAuthor().getEmail());
      mentionMessage.setText(new MailTemplates()
          .create("markerNotification")
          .replace("markerType", markerType)
          .replace("markerAuthor", "@" + markerAuthor)
          .replace("link", "https://putput.org/#/item/" + itemId)
          .replace("content", contentPreview(foundItem))
          .getText()
      );
      mailSender.send(mentionMessage);
    }
  };
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:25,代码来源:NewMarkerFlow.java

示例12: testSendMail

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
/**
 * 测试通过SpringMailSender发送简单的邮件
 */
@Test
public void testSendMail() {
    // 建立邮件消息
    SimpleMailMessage mailMessage = new SimpleMailMessage();

    // 设置收件人,寄件人 用数组发送多个邮件
    // String[] array = new String[] {"[email protected]","[email protected]"};
    // mailMessage.setTo(array);
    mailMessage.setTo(" [email protected]");
    mailMessage.setFrom("[email protected]");
    mailMessage.setSubject("测试简单文本邮件发送!");
    mailMessage.setText(" 测试我的简单邮件发送机制!");

    // 发送邮件
    senderImpl.send(mailMessage);

    System.out.println(" 邮件发送成功.. ");
}
 
开发者ID:gukt,项目名称:umbrella,代码行数:22,代码来源:MailTests.java

示例13: sendMail

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
public boolean sendMail(String to, String subject, String msg) {

		try {
			SimpleMailMessage message = new SimpleMailMessage();

			message.setFrom(from);
			message.setTo(to);
			message.setSubject(subject);
			message.setText(msg);

			javaMailSender.send(message);
			return true;

		} catch (Exception e) {
			logger.error("sendMail: ", e);
			return false;
		}
	}
 
开发者ID:pablogrela,项目名称:members_cuacfm,代码行数:19,代码来源:SpringEmailService.java

示例14: sendMail

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
private void sendMail(String recipient, String subject, String text) {
	if (!this.enabled) {
		LOG.info("Skipping sending mail to {} with body: \"{}\"", recipient, text);
		return;
	}

	SimpleMailMessage smm = new SimpleMailMessage();
	smm.setFrom(this.sendfrom);
	smm.setTo(recipient);
	smm.setSubject(subject);
	smm.setText(text);
	try {
		LOG.info("send mail to {}: {}", recipient, smm);
		javaMailService.send(smm);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:coinblesk,项目名称:coinblesk-server,代码行数:19,代码来源:MailService.java

示例15: sendEmailTolist

import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
private void sendEmailTolist(String subject,String text,String []toList) {
if(!equalsIgnoreCase(mailsenderEnable,"true")) {
    log.info("Email with subject ["+subject+"] not sent as notification is not enabled.");
    return;
}
try {
    SimpleMailMessage smm = new SimpleMailMessage();
    smm.setSubject(subject);
    smm.setFrom(mailSenderFrom);
    smm.setText(text);
    smm.setTo(toList);
    mailSender.send(smm);
    log.info("Email sent with success.\nSubject:"+subject+"\n"+text);
}
catch (Exception e) {
    log.error(e.getMessage(),e);
}

   }
 
开发者ID:renatodelgaudio,项目名称:awsroute53,代码行数:20,代码来源:Mailer.java


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