package org.itevents.service;
import com.sendgrid.*;
import org.itevents.model.User;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by max on 29.07.15.
 */
public class SendGridServiceImpl implements SendGridService {
    private String login;
    private String password;
    FileInputStream fis;
    Properties sendGrid = new Properties();



    public void sendMail(String message, User user){

        try {
            fis = new FileInputStream("src/main/resources/sendgrid.properties");
            sendGrid.load(fis);
            login = sendGrid.getProperty("login");
            password = sendGrid.getProperty("password");
        } catch (IOException e) {
            System.err.println("ERROR: File sendgrid.properties not found.");
        }

        SendGrid sendgrid = new SendGrid(login, password);
        SendGrid.Email email = new SendGrid.Email();
        email.addTo(user.getLogin());
        email.setFrom("ultimax@ukr.net");
        email.setSubject("IT Events of the week");
        email.setText(message);

        try {
            SendGrid.Response response = sendgrid.send(email);
            System.out.println(response.getMessage());
        } catch (SendGridException e) {
            System.err.println(e);
        }
    }
}

@@ -293,42 +293,15 @@
 ing 
-login;%0A    private String password
+api_key
 ;%0A  
@@ -346,16 +346,24 @@
 sendGrid
+Property
  = new P
@@ -547,16 +547,24 @@
 sendGrid
+Property
 .load(fi
@@ -579,21 +579,23 @@
         
-login
+api_key
  = sendG
@@ -597,28 +597,24 @@
 sendGrid
-.get
 Property
 (%22login%22
@@ -609,50 +609,8 @@
 erty
-(%22login%22);%0A            password = sendGrid
 .get
@@ -619,24 +619,23 @@
 operty(%22
-password
+api_key
 %22);%0A    
@@ -798,23 +798,15 @@
 rid(
-login, password
+api_key
 );%0A 

change login/pass to api_key