Merge pull request #13363 from timis1/JAVA-17293
JAVA-17293 Update Java Mail articles
This commit is contained in:
commit
aab7f72429
|
@ -25,15 +25,20 @@
|
|||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>${javax.mail.version}</version>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>angus-mail</artifactId>
|
||||
<version>${angus.mail.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.asynchttpclient</groupId>
|
||||
<artifactId>async-http-client</artifactId>
|
||||
<version>${async-http-client.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.xml.bind</groupId>
|
||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||
<version>${jakarta.bind.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.icegreen</groupId>
|
||||
<artifactId>greenmail</artifactId>
|
||||
|
@ -48,9 +53,10 @@
|
|||
|
||||
<properties>
|
||||
<httpclient.version>4.5.9</httpclient.version>
|
||||
<javax.mail.version>1.5.0-b01</javax.mail.version>
|
||||
<angus.mail.version>2.0.1</angus.mail.version>
|
||||
<async-http-client.version>2.4.5</async-http-client.version>
|
||||
<greenmail.version>1.5.8</greenmail.version>
|
||||
<jakarta.bind.version>2.3.3</jakarta.bind.version>
|
||||
<greenmail.version>2.0.0-alpha-3</greenmail.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -1,19 +1,20 @@
|
|||
package com.baeldung.mail;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import jakarta.mail.Authenticator;
|
||||
import jakarta.mail.Message;
|
||||
import jakarta.mail.Multipart;
|
||||
import jakarta.mail.PasswordAuthentication;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.Transport;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import jakarta.mail.internet.MimeBodyPart;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeMultipart;
|
||||
|
||||
public class EmailService {
|
||||
|
||||
private String username;
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
package com.baeldung.mail.mailwithattachment;
|
||||
|
||||
import javax.mail.BodyPart;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import jakarta.mail.Authenticator;
|
||||
import jakarta.mail.BodyPart;
|
||||
import jakarta.mail.Message;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.Multipart;
|
||||
import jakarta.mail.PasswordAuthentication;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.Transport;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import jakarta.mail.internet.MimeBodyPart;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeMultipart;
|
||||
|
||||
public class MailWithAttachmentService {
|
||||
|
||||
private final String username;
|
||||
|
@ -37,7 +39,7 @@ public class MailWithAttachmentService {
|
|||
props.put("mail.smtp.host", this.host);
|
||||
props.put("mail.smtp.port", this.port);
|
||||
|
||||
return Session.getInstance(props, new javax.mail.Authenticator() {
|
||||
return Session.getInstance(props, new Authenticator() {
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.baeldung.download;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -13,7 +10,11 @@ import java.security.MessageDigest;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileDownloadIntegrationTest {
|
||||
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
package com.baeldung.mail;
|
||||
|
||||
import com.icegreen.greenmail.junit.GreenMailRule;
|
||||
import com.icegreen.greenmail.util.ServerSetupTest;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import java.io.IOException;
|
||||
import com.icegreen.greenmail.junit.GreenMailRule;
|
||||
import com.icegreen.greenmail.util.ServerSetupTest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeMultipart;
|
||||
|
||||
public class EmailServiceLiveTest {
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package com.baeldung.mail.mailwithattachment;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.icegreen.greenmail.configuration.GreenMailConfiguration;
|
||||
import com.icegreen.greenmail.junit.GreenMailRule;
|
||||
import com.icegreen.greenmail.util.GreenMailUtil;
|
||||
import com.icegreen.greenmail.util.ServerSetupTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeMultipart;
|
||||
|
||||
public class MailWithAttachmentServiceLiveTest {
|
||||
|
||||
|
@ -29,7 +29,6 @@ public class MailWithAttachmentServiceLiveTest {
|
|||
.withUser(USERNAME, PASSWORD)
|
||||
);
|
||||
|
||||
@Resource
|
||||
private MailWithAttachmentService emailService;
|
||||
|
||||
@Before
|
||||
|
@ -73,5 +72,4 @@ public class MailWithAttachmentServiceLiveTest {
|
|||
return GreenMailUtil.getBody(((MimeMultipart) receivedMessage.getContent())
|
||||
.getBodyPart(2));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
<version>${tomcat.embeded.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
<version>${javax.mail.version}</version>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>angus-mail</artifactId>
|
||||
<version>${angus.mail.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.github.seancfoley/ipaddress -->
|
||||
<dependency>
|
||||
|
@ -95,7 +95,7 @@
|
|||
<seancfoley.ipaddress.version>5.3.3</seancfoley.ipaddress.version>
|
||||
<jgonian.commons-ip-math.version>1.32</jgonian.commons-ip-math.version>
|
||||
<googlecode.ipv6.version>0.17</googlecode.ipv6.version>
|
||||
<javax.mail.version>1.6.2</javax.mail.version>
|
||||
<angus.mail.version>2.0.1</angus.mail.version>
|
||||
<apache.commons-validator.version>1.7</apache.commons-validator.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -6,16 +6,16 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Folder;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.NoSuchProviderException;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Store;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import jakarta.mail.Address;
|
||||
import jakarta.mail.Folder;
|
||||
import jakarta.mail.Message;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.Multipart;
|
||||
import jakarta.mail.NoSuchProviderException;
|
||||
import jakarta.mail.Part;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.Store;
|
||||
import jakarta.mail.internet.MimeBodyPart;
|
||||
|
||||
public class DownloadEmailAttachments {
|
||||
private String downloadDirectory;
|
||||
|
@ -24,7 +24,7 @@ public class DownloadEmailAttachments {
|
|||
this.downloadDirectory = dir;
|
||||
}
|
||||
|
||||
public void downloadEmailAttachments(String host, String port, String userName, String password) throws NoSuchProviderException, MessagingException, IOException {
|
||||
public void downloadEmailAttachments(String host, String port, String userName, String password) throws MessagingException, IOException {
|
||||
Properties properties = setMailServerProperties(host, port);
|
||||
Store store = setSessionStoreProperties(userName, password, properties);
|
||||
Folder inbox = store.getFolder("INBOX");
|
||||
|
@ -67,7 +67,7 @@ public class DownloadEmailAttachments {
|
|||
return downloadedAttachments;
|
||||
}
|
||||
|
||||
public Store setSessionStoreProperties(String userName, String password, Properties properties) throws NoSuchProviderException, MessagingException {
|
||||
public Store setSessionStoreProperties(String userName, String password, Properties properties) throws MessagingException {
|
||||
Session session = Session.getDefaultInstance(properties);
|
||||
|
||||
Store store = session.getStore("pop3");
|
||||
|
|
|
@ -65,14 +65,14 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
<version>${javax.mail.version}</version>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>angus-mail</artifactId>
|
||||
<version>${angus.mail.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>javax.activation-api</artifactId>
|
||||
<version>${javax.activation.version}</version>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
<artifactId>angus-activation</artifactId>
|
||||
<version>${angus.activation.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -116,8 +116,8 @@
|
|||
<json.version>20180130</json.version>
|
||||
<logback.contrib.version>0.1.5</logback.contrib.version>
|
||||
<docx4j.version>3.3.5</docx4j.version>
|
||||
<javax.mail.version>1.6.2</javax.mail.version>
|
||||
<javax.activation.version>1.2.0</javax.activation.version>
|
||||
<angus.mail.version>2.0.1</angus.mail.version>
|
||||
<angus.activation.version>2.0.0</angus.activation.version>
|
||||
<logback.version>1.3.5</logback.version>
|
||||
<slf4j.version>2.0.4</slf4j.version>
|
||||
</properties>
|
||||
|
|
Loading…
Reference in New Issue