Demo entry 6345576

dddddd

   

Submitted by dddd on Feb 01, 2017 at 06:23
Language: Java. Code size: 1.3 kB.

@Scheduled(cron = "00 00 09 1,15 * ?")
	public void autoEmail() {
		try {
			MimeMessage message = mailSender.createMimeMessage();
			MimeMessageHelper messageHelper = new MimeMessageHelper(message, true, "UTF-8");
			messageHelper.setTo(obigoUtils.sendTo);
			messageHelper.setFrom(obigoUtils.sendFrom);
			messageHelper.setSubject(subject);

			MimeBodyPart bodypart = new MimeBodyPart();
			bodypart.setContent("PDF 파일 첨부되었습니다.", "text/html;charset=euc-kr");

			Multipart multipart = new MimeMultipart();
			multipart.addBodyPart(bodypart);

			// PDF 파일명에 로그 날짜 포함
			Calendar calendar = Calendar.getInstance();
			SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
			String fileName = formatter.format(calendar.getTime()) + "_log.pdf";
			String path = obigoUtils.path + "pdf" + File.separator + fileName;

			// PDF 만들어주는 메서드 호출 및 PDF 파일 첨부
			if (pdfpage(path)) {
				MimeBodyPart attachPart = new MimeBodyPart();
				attachPart.setDataHandler(new DataHandler(new FileDataSource(new File(path))));
				attachPart.setFileName(fileName); // 파일명
				multipart.addBodyPart(attachPart);
				message.setContent(multipart);
				mailSender.send(message);
			}
		} catch (Exception e) {
			System.out.println(e);
		}
	}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).