Skip to content

TayGov/iamp-email-service

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IAMP Email Service

The email service is a standalone service which can receive rest payloads and build/send emails.

How to send emails using Java (Spring / Rest Template)

The code block below shows an example of how to build and send a valid payload for the email service:

    @Value("classpath:/sample/test-attachment.file")
    private Resource attachment;
    
    ...
    
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("subject", "subject");
    map.add("to", "[email protected]");
    map.add("to", "[email protected]");
    map.add("cc", "[email protected]");
    map.add("bcc", "[email protected]");
    map.add("body", "body");
    FileSystemResource a = new FileSystemResource(attachment.getFile());
    map.add("attachments", a);
    
    HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<MultiValueMap<String, Object>>(map, headers);
    
    ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("/api/v1/emails"), HttpMethod.POST, entity, String.class);

The code above can also be useful for automated testing.

Copyright 2019 Province of British Columbia

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at 

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%