Reputation: 199
Im tring to send a simple email with this code using google app engine. But nothing happens, is there something i have to configure in order to use the mail api? This runs on localhost. I am using gmail as mail host.
String host = "smtp.google.com";
String to = "[email protected]";
String from = "[email protected]";
String subject = "this is a test";
String messageText = "test";
boolean sessionDebug = false;
// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
// Set debug on the Session
// Passing false will not echo debug info, and passing True will.
mailSession.setDebug(sessionDebug);
// Instantiate a new MimeMessage and fill it with the
// required information.
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = { new InternetAddress(to) };
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
// Hand the message to the default transport service
// for delivery.
Transport.send(msg);
Upvotes: 5
Views: 6768
Reputation: 11
Apparently, GAE doesn't allow the use of the admin accounts any more. you need to use the service account: [email protected]
My previous projects still work with admin accounts, but the recently created projects just don't allow me to use any of the admin accounts.
Upvotes: 1
Reputation: 337
Other than email not working on localhost or due to the sender email not being the authenticated one, I have experienced that email does not work even when the version is not the default one. I could not find this documented anywhere.
For example:
nondefaultversion-dot-myapp.appspot.com
(email does not work, no error logs)
myapp.appspot.com
(email works)
Please confirm if others have also faced this issue.
Upvotes: 0
Reputation: 11230
When running the AppEngine development server locally, anything sent via the Mail service will not actually be sent - it will just be logged to the console
See here
When an application running in the development server calls the Mail service to send an email message, the message is printed to the log. The Java development server does not send the email message.
In addition, the from
address must be (from here)
Upvotes: 10
Reputation: 2482
The sender should be your own Gmail email address instead of [email protected]
Reason is because the SMTP server needs to authenticate you.
Upvotes: 1