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


Java JavaMailSenderImpl.send方法代碼示例

本文整理匯總了Java中org.springframework.mail.javamail.JavaMailSenderImpl.send方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaMailSenderImpl.send方法的具體用法?Java JavaMailSenderImpl.send怎麽用?Java JavaMailSenderImpl.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.mail.javamail.JavaMailSenderImpl的用法示例。


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

示例1: doRun

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的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: sendEmailMsg

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的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

示例3: resetPassword

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
@RequestMapping(value = "/login/resetPassword", method = RequestMethod.POST)
@ResponseBody
public GenericResponse resetPassword(HttpServletRequest request, @RequestParam("email") String userEmail) {
    UserToolsService userService = new UserToolsService();
    User user = userService.findUserByEmail(userEmail);
    if( user == null ) {
        throw new UserNotFoundException("User could not be found by email");
    }

    String token = UUID.randomUUID().toString();
    userService.createPasswordResetTokenForUser(user, token);
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.send(constructResetTokenEmail("temptext", request.getLocale(), token, user));
    return new GenericResponse(messages.getMessage("message.resetPasswordEmail", null, request.getLocale()));
    //return new GenericResponse("Temporary email response");
}
 
開發者ID:MTUHIDE,項目名稱:CoCoTemp,代碼行數:17,代碼來源:ResetPasswordController.java

示例4: sendmail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的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

示例5: send

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public boolean send(String to, String subject, String text, String unsubscribeUrl) {
	try {
		JavaMailSenderImpl sender = (JavaMailSenderImpl) mailSender;
		MimeMessage mail = sender.createMimeMessage();
		mail.setContent(text.replaceAll("\n", "<br\\>\n").trim(),
				"text/html; charset=UTF-8");
		MimeMessageHelper helper = new MimeMessageHelper(mail, false,
				"UTF-8");
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		if (null != unsubscribeUrl) {
			mail.addHeader("List-Unsubscribe", String.format("<%s>", unsubscribeUrl));
		}
		sender.send(mail);
		LOG.trace("E-mail sent with subject: {}", subject);
		return true;
	} catch (Exception ex) {
		LOG.warn("Failed to send email (subject: " + subject + ").", ex);
		return false;
	}
}
 
開發者ID:petabyte-research,項目名稱:redflags,代碼行數:23,代碼來源:EmailSvc.java

示例6: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public void sendMail(final String from, final String to,
    final String subject, final String msg) throws MessagingException {

  // final SimpleMailMessage message = new SimpleMailMessage();
  // message.setFrom(from);
  // message.setTo(to);
  // message.setSubject(subject);
  // message.setText(msg);
  // mailSender.send(message);

  // final JavaMailSenderImpl sender = new JavaMailSenderImpl();
  mailSender = new JavaMailSenderImpl();
  final MimeMessage mimeMessage = mailSender.createMimeMessage();
  final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false,
      "utf-8");
  final String htmlMsg = msg;
  mimeMessage.setContent(htmlMsg, "text/html");
  helper.setTo(to);
  helper.setSubject(subject);
  helper.setFrom(from);
  mailSender.send(mimeMessage);

}
 
開發者ID:AURIN,項目名稱:workbenchauth,代碼行數:24,代碼來源:classMail.java

示例7: senderEmail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private void senderEmail(final Integer uid, final String username,
		final String to, final String resetKey, final String resetPwd,
		final EmailSender email, final MessageTemplate tpl) {
	JavaMailSenderImpl sender = new JavaMailSenderImpl();
	sender.setHost(email.getHost());
	sender.setPort(email.getPort());
	sender.setUsername(email.getUsername());
	sender.setPassword(email.getPassword());
	sender.send(new MimeMessagePreparator() {
		public void prepare(MimeMessage mimeMessage)
				throws MessagingException, UnsupportedEncodingException {
			MimeMessageHelper msg = new MimeMessageHelper(mimeMessage,
					false, email.getEncoding());
			msg.setSubject(tpl.getForgotPasswordSubject());
			msg.setTo(to);
			msg.setFrom(email.getUsername(), email.getPersonal());
			String text = tpl.getForgotPasswordText();
			text = StringUtils.replace(text, "${uid}", String.valueOf(uid));
			text = StringUtils.replace(text, "${username}", username);
			text = StringUtils.replace(text, "${resetKey}", resetKey);
			text = StringUtils.replace(text, "${resetPwd}", resetPwd);
			msg.setText(text);
		}
	});
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:26,代碼來源:UnifiedUserMngImpl.java

示例8: sendEmail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public void sendEmail() throws MessagingException {
    String email = backup.getEmail();
    JavaMailSenderImpl mailimpl = new JavaMailSenderImpl();
    mailimpl.setHost("smtp.163.com");
    MimeMessage mailMsg = mailimpl.createMimeMessage();
    MimeMessageHelper msgHelper = new MimeMessageHelper(mailMsg,true,"utf8");
    //set sender,receiver
    msgHelper.setTo(backup.getToemail());
    msgHelper.setFrom(email);
    msgHelper.setSubject("數據庫備份");
    msgHelper.setText("<html><head></head><body><h1>數據庫備份</h1></body></html>",true);

    msgHelper.addAttachment("study.sql",new File(backup.getSavePath() + File.separator + "study.sql"));
    msgHelper.addAttachment("blog.sql",new File(backup.getSavePath() + File.separator + "blog.sql"));

    mailimpl.setUsername(email);
    mailimpl.setPassword("liubo704");
    Properties prop = new Properties();
    prop.put("mail.smtp.auth",true);
    prop.put("mail.smtp.timeout","25000");

    mailimpl.setJavaMailProperties(prop);
    mailimpl.send(mailMsg);
}
 
開發者ID:ycsoft,項目名稱:SweetHeart,代碼行數:25,代碼來源:BackupController.java

示例9: send

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public static void send(String to,String subject,String text) {
	// 獲取JavaMailSender bean
	JavaMailSenderImpl sender = (JavaMailSenderImpl) ctx.getBean("mailSender");
	SimpleMailMessage mail = new SimpleMailMessage(); // <span															// style="color: #ff0000;">注意SimpleMailMessage隻能用來發送text格式的郵件</span>
	try {
		mail.setFrom(sender.getUsername());
		mail.setTo(to);// 接受者
		mail.setSubject(subject);// 主題
		mail.setText(text);// 郵件內容
		sender.send(mail);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:15,代碼來源:MailUtil.java

示例10: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private void sendMail(JavaMailSenderImpl mailSender, String mailFrom, String email, String subject, String message)
    throws IoTPException {
  try {
    MimeMessage mimeMsg = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, "UTF-8");
    helper.setFrom(mailFrom);
    helper.setTo(email);
    helper.setSubject(subject);
    helper.setText(message, true);
    mailSender.send(helper.getMimeMessage());
  } catch (Exception e) {
    throw handleException(e);
  }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:15,代碼來源:DefaultMailService.java

示例11: forwardSmsByMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private void forwardSmsByMail(List<ReplaySms> msgs) {
    if (msgs == null) {
        return;
    }
    for (ReplaySms sms : msgs) {
        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(mailReceiver);
        mailMessage.setFrom(mailSender);
        mailMessage.setSubject(sms.getPhone());
        mailMessage.setText("用戶回複消息,時間:" + sms.getDelivertime() + ",內容:" + sms.getContent());

        // 發送郵件
        senderImpl.send(mailMessage);

        logger.info("successfully send mail");
    }
}
 
開發者ID:booleguo,項目名稱:sam-elle,代碼行數:31,代碼來源:FetchReplaySmsTask.java

示例12: sendMessage

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private void sendMessage(String subject) {
	JavaMailSenderImpl sender = new JavaMailSenderImpl();
	sender.setPort(8025);
	sender.setHost("localhost");
	SimpleMailMessage message = new SimpleMailMessage();
	message.setText("abcd");
	message.setSubject(subject);
	message.setFrom("[email protected]");
	message.setTo("[email protected]");
	sender.send(message);
}
 
開發者ID:quirinobrizi,項目名稱:maileasy,代碼行數:12,代碼來源:MailEasyInterfaceImplTest.java

示例13: sendPlainText

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public static void sendPlainText(String to, String cc, String from, String subject, String text) {
    logger.info("sendPlainText");
    
    if (to.contains(",")) {
        to = to.replace(",", "");
    }
    if (to.contains(":")) {
        to = to.replace(":", "");
    }
            
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setTo(to);
    if (StringUtils.isNotBlank(cc)) {
        simpleMailMessage.setCc(cc);
    }
    simpleMailMessage.setBcc(ADMIN_EMAIL);
    simpleMailMessage.setFrom(from);
    simpleMailMessage.setSubject(subject);
    simpleMailMessage.setText(text);

    JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl();
    String smtpHost = ConfigHelper.getProperty("smtp.host");
    javaMailSenderImpl.setHost(smtpHost);

    logger.info("Sending e-mail to " + simpleMailMessage.getTo()[0] + " with subject \"" + simpleMailMessage.getSubject() + "\"...");
    logger.info("Text: " + simpleMailMessage.getText());
    if (EnvironmentContextLoaderListener.env != Environment.DEV) {
        javaMailSenderImpl.send(simpleMailMessage);
    }
}
 
開發者ID:elimu-ai,項目名稱:webapp,代碼行數:31,代碼來源:Mailer.java

示例14: sendMail

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private void sendMail(JavaMailSenderImpl mailSender, 
        String mailFrom, String email, 
        String subject, String message) throws ThingsboardException {
    try {
        MimeMessage mimeMsg = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, UTF_8);
        helper.setFrom(mailFrom);
        helper.setTo(email);
        helper.setSubject(subject);
        helper.setText(message, true);
        mailSender.send(helper.getMimeMessage());
    } catch (Exception e) {
        throw handleException(e);
    }
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:16,代碼來源:DefaultMailService.java

示例15: send

import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
  * 
  */
@Override
public boolean send(String from, String to, String subject, String text) {
	boolean result = false;

	ResourceBundle rb = ResourceBundleUtils.getConfigBundle();
	String smtpServer = rb.getString("email.server.smtp");

	JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
	mailSender.setHost(smtpServer);
	mailSender.setDefaultEncoding("UTF-8");

	SimpleMailMessage msg = new SimpleMailMessage();
	msg.setFrom(from);
	msg.setTo(to);
	msg.setSubject(subject);
	msg.setText(text);

	try {
		mailSender.send(msg);

		result = true;
		log.info("Odeslan email. From: " + from + ", to: " + to + ", subject: " + subject + ".");
	} catch (MailException exc) {
		log.error(exc.getMessage(), exc);
		result = false;
		log.info("NEodeslan email. From: " + from + ", to: " + to + ", subject: " + subject + ".");
	}

	return result;
}
 
開發者ID:CIT-VSB-TUO,項目名稱:ResBill,代碼行數:34,代碼來源:MailSenderServiceImpl.java


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