Nagendra Singh
Nagendra Singh

Reputation: 587

SendGrid sending not Emails using API Example in documentation

I am using same example as given in documentation :

public static void main(String[] args) throws Exception {

    Email from = new Email("****@gmail.com");
    String subject = "Sending with SendGrid is Fun";
    Email to = new Email("****@gmail.com");
    Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
    Mail mail = new Mail(from, subject, to, content);
    SendGrid sg = new SendGrid("API KEY");

    Request request = new Request();
    try {
        request.setMethod(Method.POST);
        request.setEndpoint("mail/send");
        request.setBody(mail.build());
        Response response = sg.api(request);
        System.out.println("response.getStatusCode() ------------------- "+response.getStatusCode());
        System.out.println("response.getBody() -------- "+response.getBody());
        System.out.println("response.getHeaders() -------- "+response.getHeaders());
    } catch (IOException ex) {
        throw ex;
    }
}

I can even see response code as response.getStatusCode() ------------------- 202

But still I dont get any emails. Any more configuration needs to be done on sendgrid side which I may be missing?

Upvotes: 1

Views: 3334

Answers (1)

Anish B.
Anish B.

Reputation: 16549

I'm getting mails.

The steps I followed to get the mail are as follows :

I signed up for SendGrid.

Steps :

  1. Go to the Dashboard and select "Integrate using our Web API or SMTP relay"

enter image description here

  1. Select Web API option.

enter image description here

  1. Select your desired programming language to integrate. Here, select Java.

enter image description here

  1. Put an API key name and click on create key to generate the random value for it.

enter image description here

  1. Go down on the same page to generate key and click on the check box "I've integrated the above code."

Note : Implement the code given and run it. It gives no error. Then, do this :

Then, click on the button Next:Verify Integration.

  1. It will land to the verify page.

enter image description here

  1. Click on verify Integration button. If it gets success.

Then, it will show this :

enter image description here

  1. Now, the code :

enter image description here

Output :

response.getStatusCode() ------------------- 202
response.getBody() -------- 
response.getHeaders() -------- {Server=nginx, Access-Control-Allow-Origin=https://sendgrid.api-docs.io, Access-Control-Allow-Methods=POST, Connection=keep-alive, X-Message-Id=ZBe5wF5WQN-TD9P4X9QEJw, X-No-CORS-Reason=https://sendgrid.com/docs/Classroom/Basics/API/cors.html, Content-Length=0, Access-Control-Max-Age=600, Date=Sat, 21 Mar 2020 14:09:25 GMT, Access-Control-Allow-Headers=Authorization, Content-Type, On-behalf-of, x-sg-elas-acl}
  1. Mail box : Check the Spam Folder of your mail.

enter image description here

Upvotes: 1

Related Questions