Subversion Repositories SmartDukaan

Rev

Rev 20537 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20531 kshitij.so 1
package com.hotspotstore.services;
2
 
3
import com.sendgrid.*;
4
import java.io.IOException;
5
 
6
public class SendGridMail {
7
 
8
	private static String API_KEY ="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";
9
 
10
	public static void sendMail() throws IOException {
11
		Email from = new Email("help@saholic.com");
12
		String subject = "Sending with SendGrid is Fun";
13
		Email to = new Email("kshitij.sood@saholic.com");
14
		Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
15
		Mail mail = new Mail(from, subject, to, content);
16
 
17
		SendGrid sg = new SendGrid(System.getenv(API_KEY));
18
		Request request = new Request();
19
		try {
20
			request.method = Method.POST;
21
			request.endpoint = "mail/send";
22
			request.body = mail.build();
23
			Response response = sg.api(request);
24
			System.out.println(response.statusCode);
25
			System.out.println(response.body);
26
			System.out.println(response.headers);
27
		} catch (IOException ex) {
28
			throw ex;
29
		}
30
	}
31
}