com.cerebro.provevaadin.SendConfEmail.java Source code

Java tutorial

Introduction

Here is the source code for com.cerebro.provevaadin.SendConfEmail.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cerebro.provevaadin;

import com.mailjet.client.MailjetClient;
import com.mailjet.client.MailjetRequest;
import com.mailjet.client.MailjetResponse;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.errors.MailjetSocketTimeoutException;
import com.mailjet.client.resource.Email;
import com.vaadin.ui.Button;
import com.vaadin.ui.VerticalLayout;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 *
 * @author matteo
 */
class SendConfEmail extends VerticalLayout {

    MailjetClient client;
    MailjetRequest request;
    MailjetResponse response;

    public SendConfEmail() {
        Button send = new Button("Spedisci");
        send.addClickListener((Button.ClickEvent event) -> {
            try {
                client = new MailjetClient("328cd563c1977097c524f1981f92c8b5", "896ed8a77847d131bffd62668edea39c");
                request = new MailjetRequest(Email.resource)
                        .property(Email.FROMEMAIL, "info@ambulatorio-vet-athena.it")
                        .property(Email.FROMNAME, "Matteo Casagrande").property(Email.SUBJECT, "Email di prova")
                        .property(Email.TEXTPART, "Testo semplice di prova")
                        .property(Email.HTMLPART, "<h1>Testo in html</h1>")
                        .property(Email.RECIPIENTS, new JSONArray()
                                .put(new JSONObject().put("Email", "dottmatteocasagrande@gmail.com")));
                response = client.post(request);
                System.out.println(response.getData());
            } catch (MailjetException ex) {
                Logger.getLogger(SendConfEmail.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MailjetSocketTimeoutException ex) {
                Logger.getLogger(SendConfEmail.class.getName()).log(Level.SEVERE, null, ex);
            }
        });
        this.addComponent(send);
    }

}