Skip to end of metadata
Go to start of metadata

Introduction

Useful calsses

 

Download configuration

// Download configuration of the mailbox
EmailConfiguration emailConfiguration = emailConfigurationService.getDefaultConfiguration(); //  Download default configuration
EmailConfiguration emailConfiguration1 = emailConfigurationService.get( 1L,EmailConfiguration.JOIN_CONNECTION ); // Download configuration by database  id

 

Sending an email using the EmailMessage object

Sending to many and copies and blind copies
EmailMessage emailMessage = EmailMessage.builder()
    .recipients( Arrays.asList( "test@testowy.pl", "test@testowy.pl") ) //Recipients
    .copyRecipients( Arrays.asList( "test-copy@testowy.pl", "test-copy1@testowy.pl") ) // Copy Recipients
    .hiddenCopyRecipients( Arrays.asList( "test-blindcopy@testowy.pl", "test-blindcopy1@testowy.pl") ) // Blind Copy Recipients
    .subject( "Testowy email" ) //Message title
    .content( "To jest przykładowy email" ) //Message content
    .build();
Additional configuration options
EmailMessage emailMessage = EmailMessage.builder()
    .recipient( "test@testowy.pl" ) //Message recipient
    .subject( "Testowy email" ) //Temat wiadomości
    .content( "To jest <b>przykładowy</b> email" ) //Message content
    .isHtml( true ) //Is the message content html
    .test( false ) // Is this a test message, if so it will not be sent buffered
    .build();
Attachments
//Create attachments
EmailAttachment zal1 = EmailAttachment.builder()
    .file( new File( "C:\\test\\plik1.txt" ) )
    .filename( "zal1.txt" )
    .build();

EmailAttachment zal2 = EmailAttachment.builder()
    .file( new File( "C:\\test\\plik2.txt" ) )
    .filename( "zal2.txt" )
    .build();

EmailMessage emailMessage = EmailMessage.builder()
    .recipient( "test@testowy.pl" ) //Message recipient
    .subject( "Testowy email" ) //Message title
    .content( "To jest przykładowy email" ) //Message content
    .attachments( Arrays.asList( zal1, zal2 ) ) // Attachments
    .build();
Parameter substitution in theme and content
//Tworzenie listy parametrów
Map<String,String> paramMap = new HashMap<>();
paramMap.put( "param1","Pierwszy argument" );
paramMap.put( "param2","Drugi argument" );

EmailMessage emailMessage = EmailMessage.builder()
    .recipient( "test@testowy.pl" ) //Message recipient
    .subject( "Testowy email @param1@" ) //Message title
    .content( "Test: @param2@" ) //Message content
    .params( paramMap ) // Parameters to be substituted in the title and content of the message
    .build();
Content template
// Za pomocą pliku
EmailMessage emailMessage = EmailMessage.builder()
    .recipient( "test@testowy.pl" ) //Message recipient
    .subject( "Testowy email" ) //Message title
    .template( new File( "C:\\test\\szablon.html" ) ) // Content template
    .build();
 
// Za pomocą input streama
try ( InputStream inputStream = new FileInputStream( "C:\\test\\szablon1.html" ) )
{
    EmailMessage emailMessage = EmailMessage.builder()
        .recipient( "test@testowy.pl" ) //Message recipient
        .subject( "Testowy email" ) //Message title
        .templateInputStream( inputStream ) // Content template
        .build();
}
Additional information for audits
//Tworzenie informacji dla audytu
EmailInfo emailInfo = EmailInfo.builder()
    .activityId( "zad23" )
    .processId( "proc73453" )
    .build();

EmailMessage emailMessage = EmailMessage.builder()
    .recipient( "test@testowy.pl" ) //Message recipient
    .subject( "Testowy email" ) //Message title
    .content( "Testowa zawartość" ) // Message content
    .emailInfo( emailInfo ) // Attaching information
    .build();

 

Sending an email using MimeMessage

//Session download
Session mailSession = emailService.getSession(); // Default session download
Session mailSession1 = emailService.getSession(emailConfiguration); // Downloading a session from a specific configuration

//Tworzenie wiadomości
MimeMessage mimeMessage = new MimeMessage( mailSession );
mimeMessage.addRecipients( Message.RecipientType.TO, "test@testowy.pl" ); // Message recipient
mimeMessage.setSubject( "Testowa wiadomość", "UTF-8" ); // Set title
mimeMessage.setSentDate( new Date() ); // Sending date setting
mimeMessage.setFrom( new InternetAddress( "test-nadawca@testowy.pl" ) ); // Sender setup
mimeMessage.setText( "Testowa zawartość" ); // Ustawienie zawartości

emailService.send( mimeMessage ); // Sending from a basic configuration
emailService.send( mimeMessage, emailConfiguration ); // Sending from a specific configuration
emailService.send( mimeMessage, emailInfo ); // Sending with basic configuration and information for audits
emailService.send( mimeMessage, emailConfiguration, emailInfo ); // Sending from the given configuration and information for audits

  • No labels