Hi George, thanks for the reply!
My project is a spring MVC project. I'm using a trial version of Sendgrid. I haven't updated my billing details(could this be a reason for failure).
Here's the relevant code snippet :
Method 1:
public static boolean sendEmail(String emailId) {
Sendgrid mail = new Sendgrid("my_username","my_password"); //Input: SendGrid username, password
mail.setTo(emailId) //to ID
.setFrom("
my_em...@gmail.com") //from ID
.setSubject("Sending first mail with Sendgrid") //subject
.setText("thanks for subscribing!"); //content
try {
mail.send();
}
catch (JSONException e) {
logger.info("JSON exception occured");
return false;
}
return true;
}
Method 2: I've tried the version that uses Api key too:
Email from = new Email("
my_em...@gmail.com");
String subject = "Sending first mail with Sendgrid";
Email to = new Email(emailId);
Content content = new Content("text/plain", "thanks for subscribing!");
Mail mail = new Mail(from, subject, to, content);
SendGrid sg = new SendGrid(SENDGRID_API_KEY);
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = sg.api(request);
if(response.getStatusCode()!=200) {
logger.info("response status is ", response.getStatusCode());
return false;
}