Merge branch '6.1.x'
This commit is contained in:
		
						commit
						598580020e
					
				| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2002-2022 the original author or authors.
 | 
			
		||||
 * Copyright 2002-2024 the original author or authors.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
| 
						 | 
				
			
			@ -43,6 +43,7 @@ import org.springframework.core.io.InputStreamSource;
 | 
			
		|||
import org.springframework.core.io.Resource;
 | 
			
		||||
import org.springframework.lang.Nullable;
 | 
			
		||||
import org.springframework.util.Assert;
 | 
			
		||||
import org.springframework.util.MimeTypeUtils;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Helper class for populating a {@link jakarta.mail.internet.MimeMessage}.
 | 
			
		||||
| 
						 | 
				
			
			@ -995,7 +996,8 @@ public class MimeMessageHelper {
 | 
			
		|||
	 */
 | 
			
		||||
	public void addInline(String contentId, Resource resource) throws MessagingException {
 | 
			
		||||
		Assert.notNull(resource, "Resource must not be null");
 | 
			
		||||
		String contentType = getFileTypeMap().getContentType(resource.getFilename());
 | 
			
		||||
		String contentType = (resource.getFilename() != null ?
 | 
			
		||||
				getFileTypeMap().getContentType(resource.getFilename()) : MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE);
 | 
			
		||||
		addInline(contentId, resource, contentType);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,6 +39,7 @@ import jakarta.mail.internet.InternetAddress;
 | 
			
		|||
import jakarta.mail.internet.MimeMessage;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
import org.springframework.core.io.ByteArrayResource;
 | 
			
		||||
import org.springframework.mail.MailParseException;
 | 
			
		||||
import org.springframework.mail.MailSendException;
 | 
			
		||||
import org.springframework.mail.SimpleMailMessage;
 | 
			
		||||
| 
						 | 
				
			
			@ -270,6 +271,25 @@ class JavaMailSenderTests {
 | 
			
		|||
		assertThat(sender.transport.getSentMessages()).containsExactly(message.getMimeMessage());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	void javaMailSenderWithMimeMessageHelperAndCustomResource() throws Exception {
 | 
			
		||||
		sender.setHost("host");
 | 
			
		||||
		sender.setUsername("username");
 | 
			
		||||
		sender.setPassword("password");
 | 
			
		||||
 | 
			
		||||
		MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage(), true);
 | 
			
		||||
		message.setTo("you@mail.org");
 | 
			
		||||
		message.addInline("id", new ByteArrayResource(new byte[] {1, 2, 3}));
 | 
			
		||||
 | 
			
		||||
		sender.send(message.getMimeMessage());
 | 
			
		||||
 | 
			
		||||
		assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
 | 
			
		||||
		assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
 | 
			
		||||
		assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
 | 
			
		||||
		assertThat(sender.transport.isCloseCalled()).isTrue();
 | 
			
		||||
		assertThat(sender.transport.getSentMessages()).containsExactly(message.getMimeMessage());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	void javaMailSenderWithParseExceptionOnSimpleMessage() {
 | 
			
		||||
		SimpleMailMessage simpleMessage = new SimpleMailMessage();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue