I have coded a gae engine java mail api using app.
my appengine-web.xml:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>mailapps</application>
<version>1</version>
<!--
Allows App Engine to send multiple requests to one instance in parallel:
-->
<threadsafe>true</threadsafe>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
<!--
HTTP Sessions are disabled by default. To enable HTTP sessions specify:
<sessions-enabled>true</sessions-enabled>
It's possible to reduce request latency by configuring your application to
asynchronously write HTTP session data to the datastore:
<async-session-persistence enabled="true" />
With this feature enabled, there is a very small chance your app will see
stale session data. For details, see
http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions
-->
</appengine-web-app>
When I run the app on localhost I everything works well, but when I run deploy it on gae and run it I get:
Error: Server Error The server encountered an error and could not complete your request.
If the problem persists, please report your problem and mention this error message and the query that caused it.
Whats wrong with my app? Can you please help me?
1.UPDATE_
gae logs say:
java.lang.RuntimeException: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Illegal Arguments (java.lang.IllegalArgumentException: Unauthorized Sender: Unauthorized sender))
2.UPDATE
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class FeedbackServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(FeedbackServlet.class.getName());
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = req.getParameter("name");
String description = req.getParameter("description");
String email = req.getParameter("email");
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
log.info(description + name + email + " :Daten extrahiert!");
String msgBody = name + " :Name der Person" + "\n" + description + " :Beschreibung der Person" + "\n" + email + " :EMAIL";
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]",
"It works"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]", "Your name"));
msg.setSubject("Bestellung");
msg.setText(msgBody);
log.info("Message send!");
Transport.send(msg);
} catch (Exception e) {
resp.setContentType("text/plain");
resp.getWriter().println("Something went wrong. Please try again.");
throw new RuntimeException(e);
}
resp.setContentType("text/plain");
resp.getWriter().println(
"Thanks you for your feedback. An Email has been send out.");
}
}
Thats the servlet!
There are clear restrictions for the sender Email Address. Google App Engine documentation has provided details on this.
Refer to https://developers.google.com/appengine/docs/java/mail/overview#Sending_Mail
and it will give you enough options that you can consider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With