View Javadoc
1   package com.srv4pos.server.api.email;
2   
3   import com.srv4pos.server.api.infrastructure.HttpMethod;
4   import com.srv4pos.server.api.infrastructure.StringConnectionWriter;
5   import com.srv4pos.server.api.infrastructure.credentials.Credentials;
6   import com.srv4pos.server.api.infrastructure.http.HttpHelper;
7   import com.srv4pos.server.api.infrastructure.http.Transport;
8   
9   import java.net.URL;
10  
11  import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestVoid;
12  
13  /**
14   * Sending e-mails.
15   */
16  public class EmailService {
17      private URL url;
18      private Credentials credentials;
19      private Transport transport;
20  
21      /**
22       * Constructs the service.
23       *
24       * @param url         of the server
25       * @param credentials to work with the server
26       * @param transport   to know the method to reach the server
27       */
28      public EmailService(URL url, Credentials credentials, Transport transport) {
29          this.url = url;
30          this.credentials = credentials;
31          this.transport = transport;
32      }
33  
34      /**
35       * Sends e-mail.
36       *
37       * @param emailInfo information about message
38       */
39      public void send(EmailInfo emailInfo) {
40          requestVoid("email",
41                  HttpMethod.POST,
42                  url,
43                  credentials == null ? null : credentials.toAuthentication(),
44                  null,
45                  null,
46                  new StringConnectionWriter(emailInfo.toJson()),
47                  HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
48                  transport);
49      }
50  
51  }