Email from Google App Engine doesn't arrive - java

I have been using the Email Sender (Java) in my GAE as described here and it works fine:
https://cloud.google.com/appengine/docs/java/mail/usingjavamail
I have cloned my project to a 2nd App engine (different branding, etc.) and suddenly the Email being sent doesn't arrive (yes, I've checked spam folders :-)
I created the new GAE and uploaded the code with no changes to my Email class. I added the sender email (xxx.yyy#gmail.com) to the Email API authorized senders list and they are also an Admin on the project. I get no errors or exceptions from the java code, and it says the email has been sent fine, but it never arrives. I even changed the email address to something random and I correctly received the following exception:
<stderr>: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Illegal Arguments (java.lang.IllegalArgumentException: Unauthorized Sender: Unauthorized sender))
The code works in one project, but not the other. What am I missing? Do I need to add an API?
Thank you.
Tim

Does your sender email address fit the following :
For security purposes, the sender address of a message must be one of
the following:
The Gmail or Google Apps Account of the user who is currently signedin
Any email address of the form anything#appname.appspotmail.com or
anything#appalias.appspotmail.com
Any email address listed in the Cloud Platform Console under Email API Authorized Senders
source : https://cloud.google.com/appengine/docs/python/mail/
According to your question : just check if the sender email is in App Engine > Settings > Email API authorized senders

Well it now works!
I raised the issue with Google on the back of their Issue 12786: Emails appear sent - outside world disagrees
and pointed out that their spam filter was being a little too aggressive. How can an app send emails with links back to the xxx.appspot.com if the spam filter is blocking them.
Tested it again this morning and it works
Thanks Google (aka Chris)!

Related

GMailSender on Android causing Relay Access Denied Error

I have a app through which you can send a email. This is done using the following code. The sender account is an GMail account:
GMailSender sender = new GMailSender("sender#gmail.com", "APassword");
sender.sendMail(subject,
emailText[0],
"sender#gmail.com",
receiver);
The receiver varies for testing reasons, but should be static when the app is released. Now I started testing by sending mails to another GMail account, which works fine. I continued to send mails to an outlook account, also works great. When I send emails to a private email server though, I get the following message back:
Delivery to the following recipient failed permanently:
booking#reciever.de
Technical details of permanent failure: Google tried to deliver your
message, but it was rejected by the server for the recipient domain
reciever.de by mail.reciever.de. [88.198.227.52].
The error that the other server returned was: 554 5.7.1
: Recipient address rejected: Relay access denied
I tried to figure out what this error is about, yet I have not completely understood it. I guess GMail doesn't like the receiver domain and thus does not send the email.(?)
How can I get GMail to ignore it and send it anyway? Or what else can I do to send the email? I would also greatly appreciate if someone could elaborate on this error, it is not much or well explained on the internet yet.

Email sending isn't working on Google App Engine though no errors in logs

[I have looked at all the questions related to this topic on SO but neither of them seems to explain the behaviour I am seeing].
I have two projects A (3-4 months old) and B (0.5 month old) and both use a common class to send email on Google App Engine. Both projects are currently running in the free quota.
When I invoke the common Emailer class from Project A, the email gets sent; invoking from B does not produce any errors in the log file (the logs show correct information in email fields), but the email never arrives at the recipient address. I have checked Spam folder/label and even searched entire mailbox for mail from:appspotmail.com (see below) and nothing.
I have verified that for each email sent, the email quota on Developer Console (at console.cloud.google.com/appengine/quotadetails?project=project-b&moduleId=default) registers another recipient, so obviously Google code is being invoked correctly (the email in question is for the reset password, so has only recipient).
I tried sending as admin#mydomain.com (admin#mydomain.com has been added to list of Email API authorized senders on the settings page of app B) and also as admin#project-b.appspotmail.com and neither one works.
On project A so far I have always sent email as admin#project-a.appspotmail.com (where project-a is the id of my GAE app) and have never faced any issue of this sort.
What is going on here? Is there some additional setting I am missing out on?
NB: This probably doesn't have any bearing, but mentioning in the interests of completeness: the recipient email address is of the form myaccount+xyz#gmail.com instead of the more common myaccount#gmail.com. However, manually sending email to this address from within Gmail works, so that shouldn't be an issue.
Update 1
Based on suggestions here and things that I've tried since posting this question, here are some updates:
I set up an email bounce handler as suggested but it hasn't been invoked yet (as per the logs).
Maybe it'll be invoked after waiting 24-48 hours. Let's see.
Set up account with email simplename#gmail.com and exactly the same thing (i.e., nothing) happened when I invoked Forgot password functionality.
Changed sender email to admin#project-name.appspotmail.com (instead of project-id) and got an Unauthorized sender message in an exception.
This means that the other addresses I have tried have been authorized senders as I never saw this exception with them.
The best way to troubleshoot App Engine Email delivery problems is to Configure Email Bounce Notification. As Emails are delivered asynchronously, any delivery problems will result in a bounce to the specified sender.

How to get google app engine admin mail address?

Is there a way in Google App Engine (Java) to get the the email address of the admin that is allowed to send mails without hardcoding it somewhere?
Currently I use the Java System property in the appengine-web.xml. Something like the uploader of the app would be fine, too.
Background of this question: I create an app that students have to clone in their own GAE instance. Hence the cloning effort should be minimized as much as possible.
I believe what you are looking for is the way to figure out the email id that is valid to send out mail from. You can figure out the appid dynamically using the App Identity API and construct the sender email id dynamically.
https://cloud.google.com/appengine/docs/java/appidentity/
Once you have the appid you can construct the email id as string#appid.appspotmail.com where 'string' can be anything and 'appid' is the appid you got from the Identity API.
The format of the sending e-mail address seems to have changed (as of 2016) and so I would use:
msg.setFrom(new InternetAddress(SystemProperty.applicationId.get() + "#appspot.gserviceaccount.com"));

Can't set the email sender in JavaMail - Spring [duplicate]

I want to send an email from A to B, with HEADER and CONTENT through gmail.
How to do that by PHP?
I've specified the FROM (from#example.com), but when I receive the email, it's still from my gmail account (abc#gmail.com).
$mail->From = "from#example.com";
$mail->FromName = "Mailer";
$mail->AddAddress("abc12#163.example", "Josh Adams");// name is optional
$mail->AddReplyTo("abc12#qq.example", "Information");
How do I change the FROM part?
The short answer - you can't.
Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.
The SMTP feature of gmail isn't intended to be an open or relay service. If it allowed any values for the From header, it would significantly dilute Google's standing with spam services, as there would be no way to verify the credentials of the sender.
You need to consider alternatives. How are you planning to host your script/application/website when it's finished: virtually every hosting solutions (shared/vps/dedicated server) will come pre-configured with an email transfer solution: be it sendmail or postfix on *nix, or IIS on Windows.
If you are intent on using gmail then you could:
Setup a dedicated myapp#gmail.com account
If you own the domain you are supposedly sending from, use the free gmail for domains, and setup a myapp#mydomain.example account.
====
Edit June 2015
It was suggested that GMail does allow sending via different addresses. As far as I can tell, this is for sending via the GMail wep app, and utilises your existing external SMTP server, which is not relevant to the original question.
====
Edit Nov 2013
Seeing as this is still getting a trickle of votes. A quick update.
Google have withdrawn their free GMail for domains. There are plenty of other free services around. One of note is Mandrill - a one-to-one email service intended for transactional emails (e.g. ecommerce orders etc.). It's ran by MailChimp, who pretty much know all there is to know about sending email at volume. They also give you 12k/month free, which is rather nice.
This question and correct answer may be relevant:
When using Gmail for SMTP, can you set a different "from" address?
Gmail requires you to validate From addresses before sending mail as that email address. So you need to add a new sender in your personal gmail account and validate it.
Doing so will allow you to authenticate with youremail#gmail.com and send email from from#example.com
Unlike everyone else, I'll take the plunge and make the assumption that by letters you mean emails...
But I'm not sure what you are getting at when you mention that it should include "Headers and Content". Do you want to forward emails? Do you want the emails from A to appear as though they came from B's gmail account in the headers? Are you building some sort of gmail client?
The easiest way to send an email with PHP is with the mail function. This example comes straight from their documentation:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
If you want the headers to appear from A's gmail and not to simply change the from/reply to part, you'd have to use gmail as the SMTP server. I don't know if you can set that at the script level.
The answer above are not quite correct.
You are definitely able to specify any senders as long as you own the other email address.
As the help page explains:
On your computer, open Gmail.
In the top right, click Settings.
Click the Accounts and import or Accounts tab.
In the "Send mail as" section, click Add another email address.
Enter your name and the address you want to send from.
Click Next Step and then Send verification.
For school or work accounts, enter the SMTP server (for example, smtp.gmail.com or smtp.yourschool.edu) and the username and password on that account.
Click Add Account.
Once that email is added successfully,
you can send email on the behalf of the new email address in gmail.
Google will not rewrite your from email in this way while you're sending email via Google SMTP.
You need to go to GMAIL settings and add new alias.
You will be asked SMTP information, which is basically useless, since you are using SMTP to send email, BUT the catch is that if your alias is on Google Suite domain it will be added just with simple email confirmation!
Once you have the alias there, you can change "From" header in your SMTP email.
NOTE: You cannot change the "From" address to whatever#dude.example, that's just how Gmail works and is the reason it's trusted.
If the reason you want to use gmail is because you don't want to set up an MTA (the reason you stated in a comment to this answer), you have 2 options:
If the web server is at your
home/work place; use your ISP's
smtp-server
If the web server is at a dedicated
hosting center, ask them what
smtp-server to use.

How to make reply of an email becomes a HttpRequestServlet to a web application?

I got a requirement which I don't know how to get started.
Requirement:
The application will send emails to clients (using org.springframework.mail.javamail.JavaMailSender) with same "from email address" as support#mydomain.com. Also the email content will have some hidden information such as client_id. If the client reply back to that email, I need to get that as an HttpServletRequest to a Servlet so that I can process it.
EDIT:
This web application does not have google app engine setup, but my requirement is matching similar to this link.
When someone replies to the mail you sent him that mail will go to the POP3 server configured for your domain. From this SMTP server you can read this mail using the Java Mail API. You can have a Spring timer task to keep polling this mailbox after every few seconds.
I would look at the below resources to see how to read mail from the POP3 server -
Using JavaMail API -
http://metoojava.wordpress.com/2010/03/21/java-code-to-receive-mail-using-javamailapi
Using Spring -
http://blog.solidcraft.eu/2011/04/read-emails-from-imap-with-spring.html
Better and popular solution is to have a link in your email and asking user to click it and asking specifically not to reply to this email (from address can be noreply#domain.com)
For getting a servlet call in an email reply, you need to use
http://javamail.kenai.com/nonav/javadocs/com/sun/mail/pop3/package-summary.html
Keep polling for new emails in your reply address(for eg support#domain.com) using POP, and when new email comes trigger a httprequest(HttpClient? ).
On a related note you can add user_id and similar stuff using a + in reply email address
For eg support#domain.com and support+uid_21_catid_32#domain.com will deliver to same address. Everything after + is ignored. But you will get this info in reply email event as to address and decide on who is the user.This could be a security concern for sure if not properly implemented.

Categories

Resources