public void send()

in src/main/java/transcribe/EmailService.java [54:131]


	public void send(String To, String SUBJECT, File fileName) throws AddressException, MessagingException, IOException {

		System.out.println("In EmailService -> Send function()...");

		Session session = Session.getDefaultInstance(new Properties());

		MimeMessage message = new MimeMessage(session);

		message.setSubject(SUBJECT, "UTF-8");
		message.setFrom(new InternetAddress(SENDER));
		message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(To));
		//message.setContent(BODY, "text/plain; charset=UTF-8");
		
		MimeMultipart msg_body = new MimeMultipart("alternative");
        
        // Create a wrapper for the HTML and text parts.        
        MimeBodyPart wrap = new MimeBodyPart();
        
        // Define the text part.
        MimeBodyPart textPart = new MimeBodyPart();
        textPart.setContent(BODY_TEXT, "text/plain; charset=UTF-8");
                
        // Define the HTML part.
        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setContent(BODY_HTML,"text/html; charset=UTF-8");
                
        // Add the text and HTML parts to the child container.
        msg_body.addBodyPart(textPart);
        msg_body.addBodyPart(htmlPart);
        
        // Add the child container to the wrapper object.
        wrap.setContent(msg_body);
        
        // Create a multipart/mixed parent container.
        MimeMultipart msg = new MimeMultipart("mixed");
        
        // Add the parent container to the message.
        message.setContent(msg);
        
        // Add the multipart/alternative part to the message.
        msg.addBodyPart(wrap);
        
        // Define the attachment
        MimeBodyPart att = new MimeBodyPart();
        DataSource fds = new FileDataSource(fileName);
        att.setDataHandler(new DataHandler(fds));
        att.setFileName(fds.getName());
        
        // Add the attachment to the message.
        msg.addBodyPart(att);
		
		try {
			System.out.println("Attempting to send an email through Amazon SES "
					+"using the AWS SDK for Java...");

			AmazonSimpleEmailService client = 
					AmazonSimpleEmailServiceClientBuilder
					.standard()
					.withRegion(regions)
					.build();

			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
			message.writeTo(outputStream);
			RawMessage rawMessage = 
					new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));

			SendRawEmailRequest rawEmailRequest = 
					new SendRawEmailRequest(rawMessage);

			client.sendRawEmail(rawEmailRequest);
			System.out.println("Email sent!");
		} catch (Exception ex) {
			System.out.println("Email Failed");
			System.err.println("Error message: " + ex.getMessage());
			//processFailedEmail(To, SUBJECT, BODY);
			ex.printStackTrace();
		}
	}