GAE Web app sending mail using SendGrid

257 views
Skip to first unread message

Rashmi S

unread,
Aug 14, 2018, 9:03:01 AM8/14/18
to Google App Engine
Trying to send mails using Sendgrid in my gae project. I referred to these docs https://cloud.google.com/appengine/docs/standard/java/mail/sendgrid
It works perfectly in the localhost. But on deploying to app engine standard, it works only once, that is, I'm able to send an email only once. I've checked the logs too, it doesn't show any error.. Any idea why this is happening? Anyone with a similar problem? 

George (Cloud Platform Support)

unread,
Aug 14, 2018, 1:52:00 PM8/14/18
to Google App Engine
Hello Rashmi, 

Have you followed all steps in the referred document? Authentication works well? How does your email-related code looks like? A sample of your code would greatly help in setting the basis of further investigations. You may consider having a look at the SendGrid Tutorial, to make sure you have covered all needed steps, to secure full functionality in the deployed app. 

Rashmi S

unread,
Aug 14, 2018, 3:02:55 PM8/14/18
to Google App Engine
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;
}


Rashmi S

unread,
Aug 14, 2018, 3:02:55 PM8/14/18
to Google App Engine
Yes, authentication works well.
Message has been deleted

George (Cloud Platform Support)

unread,
Aug 15, 2018, 5:23:42 PM8/15/18
to google-a...@googlegroups.com
At this stage, we'll need your project ID for closer and more in-depth inspection. As this is private information, you should send it by private message, using the drop-down menu of the "reply" button at the top right of a posting window. 

It may be worthwhile mentioning here that this discussion group is oriented more towards general opinions, trends and issues of general nature touching the app engine. For coding and programming architecture, you are better served in a forum such as stackoverflow, where experienced programmers are within reach and ready to help. 

Rashmi S

unread,
Aug 20, 2018, 9:27:25 AM8/20/18
to Google App Engine
Just want to confirm, is updation of billing account necessary even for free trial versions of sendgrid or mailjef. Will it not work without payment details? And could it be possible that these services, even recaptcha is failing with an IOexception or server error?...with reference to this doc: https://cloud.google.com/appengine/docs/standard/java/issue-requests#java_8_runtime_vs_java_7_behavior . Can anyone clarify..

George (Cloud Platform Support)

unread,
Aug 20, 2018, 2:03:57 PM8/20/18
to google-a...@googlegroups.com
There are a lot of advantages offered by SendGrid to free account holders. You may check details on the SendGrid pricing page. Payment details are not requested on that page. 

How did you get your application ready? You are encouraged to read the "Preparing the application" sub-chapter of the SendGrid tutorial. Have you followed each and every step listed on that page? 

You seem to need help for a coding issue; it may be worth mentioning: this is a tracker for Cloud SDK specific issues. When it comes strictly to programming and coding, you’ll be at an advantage to rather post your questions on Stackoverflow, to gain this way access to a large number of experts; Stackoverflow and other similar forums are meant to provide help with coding. 

George (Cloud Platform Support)

unread,
Aug 23, 2018, 3:04:44 PM8/23/18
to Google App Engine
Have you followed each and every step listed in "Preparing the application" sub-chapter of the SendGrid tutorial?

Rashmi S

unread,
Aug 24, 2018, 9:05:33 AM8/24/18
to google-a...@googlegroups.com
Yes, I did.

On Fri, Aug 24, 2018 at 12:34 AM 'George (Cloud Platform Support)' via Google App Engine <google-a...@googlegroups.com> wrote:
Have you followed each and every step listed in "Preparing the application" sub-chapter of the SendGrid tutorial?

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/6dc115d3-5f3f-4ba2-a8cd-98d874b716f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

George (Cloud Platform Support)

unread,
Aug 24, 2018, 3:38:16 PM8/24/18
to Google App Engine
If you would like us to look more in-depth in the issue, you should write a private message with your project ID. You can do this using the drop-down menu of the reply button, at the top-right of the message window. 

Rashmi S

unread,
Sep 7, 2018, 12:02:44 PM9/7/18
to Google App Engine
I have solved the problem. I had to use Urlfetch configuration in appengine-web.xml and use URLFetch class instead of HttpURLConnection. It works now. Thanks for the help!

Alexis CAPGEMINI

unread,
Jul 15, 2020, 8:20:07 AM7/15/20
to Google App Engine
Can you please explain how you did this ?

I'm still stuck with an error here :      SendGrid sendgrid = new SendGrid( System.getenv("SENDGRID_SENDER"));  

Thanks

Adam Jack

unread,
Jul 15, 2020, 1:54:05 PM7/15/20
to google-a...@googlegroups.com
I don't know the background here, but in case any of this helps:

Do you have an API key from SendGrid?


In your appengine-web.xml  set the environment variable to pass that API key into:

<env-variables>
 
<env-var name="SENDGRID_SENDER" value="{{STICK THE API KEY VALUE HERE}}" />
</env-variables>



Sorry if I am off base, it just looks similar to what I am doing (with Go.)

regards,

Adam

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.


--
Responserack
- incidents happen, response is crafted...
Reply all
Reply to author
Forward
0 new messages